android - There is no error shown and when any of the buttons in the activity are pressed, the app forces close? -
why buttons forcing app close, there no errors have been highlighted , new android development, can't find problem. appreciated thanks.
this xml
<linearlayout android:layout_width="fill_parent" android:layout_height="447dp" android:background="@drawable/background" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".categories" > <button android:id="@+id/author" android:layout_width="match_parent" android:layout_height="45dp" android:layout_alignparentend="true" android:layout_alignparentstart="true" android:background="@drawable/buttonpress" android:onclick="author" android:text="@string/author" android:textcolor="#fa6900" android:textsize="21sp" /> <button android:id="@+id/religion" android:layout_width="match_parent" android:layout_height="50dp" android:layout_margintop="22dp" android:background="@drawable/buttonpress" android:onclick="religion" android:text="@string/religion" android:textcolor="#fa6900" android:textsize="21sp" /> <button android:id="@+id/politician" android:layout_width="match_parent" android:layout_height="45dp" android:layout_margintop="22dp" android:background="@drawable/buttonpress" android:onclick="politician" android:text="@string/politician" android:textcolor="#fa6900" android:textsize="21sp" /> <button android:id="@+id/happy" android:layout_width="match_parent" android:layout_height="45dp" android:layout_margintop="23dp" android:background="@drawable/buttonpress" android:onclick="happiness" android:text="@string/happy" android:textcolor="#fa6900" android:textsize="21sp" /> <button android:id="@+id/sport" android:layout_width="match_parent" android:layout_height="45dp" android:layout_margintop="22dp" android:background="@drawable/buttonpress" android:onclick="sport" android:text="@string/sport" android:textcolor="#fa6900" android:textsize="21sp" /> </linearlayout> </scrollview>
java
package com.android.motivateme3; import android.os.bundle; import android.os.vibrator; import android.app.activity; import android.content.context; import android.content.intent; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.support.v4.app.navutils; public class categories extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_categories); // show button in action bar. setupactionbar(); } /** * set {@link android.app.actionbar}. */ private void setupactionbar() { getactionbar().setdisplayhomeasupenabled(true); } public void sport(view v) { intent intent = new intent(getapplicationcontext(), sport.class); vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); startactivity(intent); } public void religion(view v) { intent intent = new intent(getapplicationcontext(), religion.class); vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); startactivity(intent);} public void author(view v) { intent intent = new intent(getapplicationcontext(), author.class); vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); startactivity(intent);} public void politician(view v) { intent intent = new intent(getapplicationcontext(), politician.class); vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); startactivity(intent);} public void happiness(view v) { intent intent = new intent(getapplicationcontext(), happiness.class); vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); startactivity(intent);} @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.categories, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: // id represents home or button. in case of // activity, button shown. use navutils allow users // navigate 1 level in application structure. // more details, see navigation pattern on android design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // navutils.navigateupfromsametask(this); return true; } return super.onoptionsitemselected(item); } }
logcat
05-04 16:08:41.014: d/memalloc(28579): /dev/pmem: mapped buffer base:0x60519000 size:18690048 offset:14921728 fd:73 05-04 16:08:41.054: d/memalloc(28579): /dev/pmem: mapped buffer base:0x61a6c000 size:35233792 offset:31465472 fd:79 05-04 16:08:41.064: d/openglrenderer(28579): flushing caches (mode 0) 05-04 16:08:41.074: d/memalloc(28579): /dev/pmem: unmapping buffer base:0x5c63f000 size:31465472 offset:27697152 05-04 16:08:41.074: d/memalloc(28579): /dev/pmem: unmapping buffer base:0x5ebfb000 size:10366976 offset:6598656 05-04 16:08:41.084: d/memalloc(28579): /dev/pmem: unmapping buffer base:0x5f5de000 size:14921728 offset:11153408 05-04 16:08:41.824: d/memalloc(28579): /dev/pmem: mapped buffer base:0x5c63f000 size:14921728 offset:11153408 fd:64 05-04 16:08:42.344: d/androidruntime(28579): shutting down vm 05-04 16:08:42.344: w/dalvikvm(28579): threadid=1: thread exiting uncaught exception (group=0x40ac4210) 05-04 16:08:42.354: e/androidruntime(28579): fatal exception: main 05-04 16:08:42.354: e/androidruntime(28579): java.lang.runtimeexception: unable start activity componentinfo{com.android.motivateme3/com.android.motivateme3.author}: java.lang.classcastexception: android.widget.textview cannot cast android.widget.imagebutton 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread.performlaunchactivity(activitythread.java:1967) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1992) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread.access$600(activitythread.java:127) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread$h.handlemessage(activitythread.java:1158) 05-04 16:08:42.354: e/androidruntime(28579): @ android.os.handler.dispatchmessage(handler.java:99) 05-04 16:08:42.354: e/androidruntime(28579): @ android.os.looper.loop(looper.java:137) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread.main(activitythread.java:4441) 05-04 16:08:42.354: e/androidruntime(28579): @ java.lang.reflect.method.invokenative(native method) 05-04 16:08:42.354: e/androidruntime(28579): @ java.lang.reflect.method.invoke(method.java:511) 05-04 16:08:42.354: e/androidruntime(28579): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:823) 05-04 16:08:42.354: e/androidruntime(28579): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:590) 05-04 16:08:42.354: e/androidruntime(28579): @ dalvik.system.nativestart.main(native method) 05-04 16:08:42.354: e/androidruntime(28579): caused by: java.lang.classcastexception: android.widget.textview cannot cast android.widget.imagebutton 05-04 16:08:42.354: e/androidruntime(28579): @ com.android.motivateme3.author.setupactionbar(author.java:39) 05-04 16:08:42.354: e/androidruntime(28579): @ com.android.motivateme3.author.oncreate(author.java:28) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activity.performcreate(activity.java:4465) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 05-04 16:08:42.354: e/androidruntime(28579): @ android.app.activitythread.performlaunchactivity(activitythread.java:1931) 05-04 16:08:42.354: e/androidruntime(28579): ... 11 more 05-04 16:08:49.964: i/process(28579): sending signal. pid: 28579 sig: 9 05-04 16:11:35.094: d/memalloc(28746): /dev/pmem: mapped buffer base:0x5f932000 size:10366976 offset:6598656 fd:70
manifest
<uses-sdk android:minsdkversion="11" android:targetsdkversion="15" /> <uses-feature android:name="@string/hello_world" /> <uses-feature android:name="@string/politician" /> <uses-feature android:name="@string/sport" /> <uses-feature android:name="@string/religion" /> <uses-feature android:name="@string/author" /> <uses-feature android:name="@string/happy" /> <uses-feature android:name="@string/responseno" /> <uses-feature android:name="@string/responseyes" /> <uses-permission android:name="android.permission.vibrate" /> <application android:allowbackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.android.motivateme3.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.android.motivateme3.sport" android:label="@string/title_activity_sport" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.religion" android:label="@string/title_activity_religion" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.author" android:label="@string/title_activity_author" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.politician" android:label="@string/title_activity_politician" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.sports" android:label="@string/title_activity_sports" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.happiness" android:label="@string/title_activity_happiness" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.categories" /> </activity> <activity android:name="com.android.motivateme3.feedback" android:label="@string/title_activity_feedback" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.mainactivity" /> </activity> <activity android:name="com.android.motivateme3.settingsactivity" android:label="@string/title_activity_settings" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.mainactivity" /> </activity> <activity android:name="com.android.motivateme3.categories" android:label="@string/title_activity_categories" android:parentactivityname="com.android.motivateme3.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.android.motivateme3.mainactivity" /> </activity> <activity android:name="com.android.motivateme3.favourites" android:label="@string/title_activity_favourites" > </activity> </application> </manifest>
author activity java package com.android.motivateme3;
import java.util.random; import android.os.bundle; import android.os.vibrator; import android.app.activity; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.imagebutton; import android.widget.textview; import android.support.v4.app.navutils; import android.annotation.targetapi; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.os.build; public class author extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_author); // show button in action bar. setupactionbar(); } /** * set {@link android.app.actionbar}, if api available. */ @targetapi(build.version_codes.honeycomb) private void setupactionbar() { if (build.version.sdk_int >= build.version_codes.honeycomb) { getactionbar().setdisplayhomeasupenabled(true); imagebutton nextquote = (imagebutton)findviewbyid(r.id.next); final textview display = (textview) findviewbyid(r.id.textview1); nextquote.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // todo auto-generated method stub vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); random numgen = new random(); int rnumber = numgen.nextint(10); if (rnumber == 0) { display.settext(r.string.author1); } else if (rnumber == 1) { display.settext(r.string.author2); } else if (rnumber == 2) { display.settext(r.string.author3); } else if (rnumber == 3) { display.settext(r.string.author4); } else if (rnumber == 4) { display.settext(r.string.author5); } else if (rnumber == 5) { display.settext(r.string.author6); } else if (rnumber == 6) { display.settext(r.string.author7); } else if (rnumber == 7) { display.settext(r.string.author8); } else if (rnumber == 8) { display.settext(r.string.author9); } else if (rnumber == 9) { display.settext(r.string.author10); } } }); } imagebutton sharing = (imagebutton)findviewbyid(r.id.share); sharing.setonclicklistener(new view.onclicklistener() { public void onclick(view v){ vibrator vibrator = (vibrator)getsystemservice(context.vibrator_service); vibrator.vibrate(25); textview text = (textview)findviewbyid(r.id.textview1); string quote = text.gettext().tostring();{ intent shareintent = new intent(android.content.intent.action_send); shareintent.settype("plain/text"); shareintent.putextra(android.content.intent.extra_subject, "this great quote (from motivate me! app)"); shareintent.putextra(android.content.intent.extra_text, quote); startactivity(intent.createchooser(shareintent, "share via:"));}};});} @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.author, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: // id represents home or button. in case of // activity, button shown. use navutils allow users // navigate 1 level in application structure. // more details, see navigation pattern on android design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // navutils.navigateupfromsametask(this); return true; } return super.onoptionsitemselected(item); } }
xml author
<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:background="@drawable/background" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".author" > <imagebutton android:id="@+id/next" android:layout_width="140dp" android:layout_height="50dp" android:layout_alignright="@+id/textview1" android:layout_below="@+id/textview1" android:layout_margintop="14dp" android:background="@drawable/buttonpress" android:contentdescription="@string/next" android:onclick="nextquote" android:src="@drawable/navigationnextitem" /> <imagebutton android:id="@+id/share" android:layout_width="140dp" android:layout_height="50dp" android:layout_alignleft="@+id/textview1" android:layout_aligntop="@+id/next" android:background="@drawable/buttonpress" android:contentdescription="@string/share" android:onclick="sharing" android:src="@drawable/socialshare" /> <textview android:id="@+id/textview1" android:layout_width="300dp" android:layout_height="300dp" android:layout_centerhorizontal="true" android:layout_margintop="14dp" android:background="@drawable/button_shape" android:text="@string/getstarted" android:textcolor="#ff6900" android:textsize="23sp" /> </relativelayout>
can go project menu in eclipse , clean ..after clean run project , see if resolves issue:
Comments
Post a Comment