Y
Yuck
Neues Mitglied
- 1
ich hab im internet schon zig sachen gelesen und versucht finde aber den fehler nicht.
Es ist absolut simple, einfach nur ein button und etwas text - bevor ich es ausführen sollte gab er mir keine fehler an.
Nun gibt er einen fehler bei setContentView(R.layout.acitivty_main) an - cannot resolve method, cannot resolve symbol r..
~~ ich bin ratlos...
Main Activity
AnotherActivity
Die XML dateien scheinen fehlerlos zu sein
xml main
xml another
strings.xml
android manifest
build.gradle
überall wo class R genutzt wird gibt er mir einen fehler. Sprich in den beiden java dateien mainactivity und anotheractivity
wenn ich import android.R; einfüge was android als lösung vorschlägt gibt es die gleiche fehlermedlung bei setContentView(R.layout.activity_main) und findViewById(R.id.btn)
Es ist absolut simple, einfach nur ein button und etwas text - bevor ich es ausführen sollte gab er mir keine fehler an.
Nun gibt er einen fehler bei setContentView(R.layout.acitivty_main) an - cannot resolve method, cannot resolve symbol r..
~~ ich bin ratlos...
Main Activity
Code:
package com.example.sampleapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
[B] setContentView[U]([COLOR=Red]R[/COLOR].layout.activity_main)[/U];[/B]
OnClickListener listnr=new OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent("AnotherActivity");
startActivity(i);
}
};
Button btn =(Button) findViewById[COLOR=Red][COLOR=Black]([/COLOR][B][U]R.[/U][/B][/COLOR][B][U]id.btn)[/U][/B];
btn.setOnClickListener(listnr);
}
}
AnotherActivity
Code:
package com.example.sampleapp;
import android.app.Activity;
import android.os.Bundle;
public class AnotherActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
[B]setContentView([U][COLOR=Red]R[/COLOR].layout.activity_another);[/U][/B]
}
}
xml main
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="125dp"
android:layout_height="wrap_content"
android:text="@string/test123" />
<Button
android:id="@+id/btn"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:text="@string/lblBtn" />
</LinearLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lblTxt"
/>
</LinearLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">sampleapp</string>
<string name="test123">test123</string>
<string name="lblBtn">Open Activity Demo</string>
<string name="btn"></string>
<string name="lblTxt">passt</string>
<string name="menu_settings">Settings</string>
</resources>
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sampleapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sampleapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.sampleapp.AnotherActivity"
android:label="@string/app_name">
<intent-filter >
<action android:name="in.wptrafficanalyzer.AnotherActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
Code:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
wenn ich import android.R; einfüge was android als lösung vorschlägt gibt es die gleiche fehlermedlung bei setContentView(R.layout.activity_main) und findViewById(R.id.btn)
Zuletzt bearbeitet: