android - Sudoku crashes when 'about' button is clicked -
hi new android , have been trying simple sudoku application. facing problem now,whenever click "about" button applocation tends stop , takes me menu screen. can suggest problem crash??
below here code:
sudoku.java
public class sudoku extends activity implements onclicklistener { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_sudoku); view continuebutton=findviewbyid(r.id.button1); continuebutton.setonclicklistener(this); view newbutton=findviewbyid(r.id.button2); newbutton.setonclicklistener(this); view aboutbutton=findviewbyid(r.id.button3); aboutbutton.setonclicklistener(this); view exitbutton=findviewbyid(r.id.button4); exitbutton.setonclicklistener(this); } public void onclick(view v){ switch(v.getid()){ case r.id.button3: intent = new intent(this, about.class); startactivity(i); break; case r.id.button4: finish(); break; } } @override public boolean oncreateoptionsmenu(menu menu) { super.oncreateoptionsmenu(menu); menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu, menu); return true; } }
about.java
public class extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.about); } }
about.xml:
public class extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.about); } }
string.xml:
<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">sudoku</string> <string name="action_settings">settings</string> <string name="hello_world">application sudoku</string> <string name="continue_label">continue</string> <string name="new_game_label">new game</string> <string name="about_label">about</string> <string name="exit_label">exit</string> <string name="about_title">about android sudoku</string> <string name="about_text">\sudoku logic-based number placement puzzle.
starting partially completed 9x9 grid, objective fill grid each row, each column, , each of 3x3 boxes (also called blocks) contains digits 1 9 once..
activity_sudoku.xml
<relativelayout 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" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:background="@color/background" tools:context=".sudoku" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:textstyle="italic" /> <tablelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:stretchcolumns="*"> <tablerow > <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview1" android:layout_below="@+id/textview1" android:layout_margintop="22dp" android:text="@string/continue_label" android:textstyle="italic" /> <button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/button1" android:layout_below="@+id/button1" android:layout_margintop="21dp" android:text="@string/new_game_label" android:textstyle="italic" /> </tablerow> <tablerow > <button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="16dp" android:text="@string/about_label" /> <button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="16dp" android:text="@string/exit_label" /> </tablerow> </tablelayout> </relativelayout>
sudoku manifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.example.sudoku" 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="org.example.sudoku.sudoku" 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="org.example.sudoku.about" android:label="@string/about_title" android:theme="@android:style/theme.dialog"> </activity> </application> </manifest>
you should try adding intent-filter manifest.xml. faced problem lot during starting android prog. add such as:
<activity android:name="org.example.sudoku.sudoku" 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="org.example.sudoku.about" android:label="@string/about_title" android:theme="@android:style/theme.dialog"> <intent-filter> <action android:name="org.example.sudoku.about" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity>
later in sudoku.java update part:
case r.id.button3: intent = new intent(this, about.class); startactivity(i); break;
update above as:
case r.id.button3: startactivity(new intent("org.example.sudoku.about")); break;
this should solve problem.
Comments
Post a Comment