Android Onclick Error
I am currently working through a Java Android book and have hit a problem. I am creating a basic sudoku app and am trying to add a OnClickListener so that when someone hits the 'Ab
Solution 1:
I'm not sure if it's the reason, but ur manifest file seems messed up. Those two activity tags are mingled together. You should change the application part to:
<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"><activityandroid:name=".Sudoku"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".About"android:label="@string/about_title"></activity></application>
Solution 2:
you have defined activity wrong in manifest. A part of it should be as below:
<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"><activityandroid:name=".Sudoku"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".About"android:label="@string/about_title"></activity></application>
Solution 3:
ButtonaboutButton= (Button)findViewById(R.id.about_button);
if (aboutButton != null)
aboutButton.setOnClickListener(this);
else
Log.e("MyTag", "aboutButton not found on View");
Also make sure to edit your manifest.
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="org.example.sudoku"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="8" /><applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"><activityandroid:name=".Sudoku"android:label="@string/app_name" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".About"android:label="@string/about_title"></activity></application></manifest>
This should work.
Solution 4:
<activityandroid:name=".Sudoku"android:label="@string/app_name" ><activityandroid:name=".About"android:label="@string/about_title"></activity><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
should be :
<activity>
android:name=".Sudoku"android:label="@string/app_name" >
<intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter>
</activity>
<activityandroid:name=".About"android:label="@string/about_title"></activity>
Post a Comment for "Android Onclick Error"