eclipse - FATAL EXCEPTION: main while Android application running -
i'm total newbie , i'm studying @ time make android applications. used 1 of tutorials. things well, reasons application began crush every time i'm going launch it.
i tried hard see in logcat reason didn't manage to. grateful if tell me going on.
here logcat:
08-30 19:13:21.955: w/dalvikvm(7272): threadid=1: thread exiting uncaught exception (group=0x41869d58) 08-30 19:13:21.955: e/androidruntime(7272): fatal exception: main 08-30 19:13:21.955: e/androidruntime(7272): process: alesto.androidinterview, pid: 7272 08-30 19:13:21.955: e/androidruntime(7272): java.lang.runtimeexception: unable start activity componentinfo{alesto.androidinterview/alesto.androidinterview.simplequestion}: java.lang.nullpointerexception 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread.performlaunchactivity(activitythread.java:2209) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2259) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread.access$800(activitythread.java:149) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread$h.handlemessage(activitythread.java:1210) 08-30 19:13:21.955: e/androidruntime(7272): @ android.os.handler.dispatchmessage(handler.java:102) 08-30 19:13:21.955: e/androidruntime(7272): @ android.os.looper.loop(looper.java:136) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread.main(activitythread.java:5110) 08-30 19:13:21.955: e/androidruntime(7272): @ java.lang.reflect.method.invokenative(native method) 08-30 19:13:21.955: e/androidruntime(7272): @ java.lang.reflect.method.invoke(method.java:515) 08-30 19:13:21.955: e/androidruntime(7272): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:781) 08-30 19:13:21.955: e/androidruntime(7272): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 08-30 19:13:21.955: e/androidruntime(7272): @ dalvik.system.nativestart.main(native method) 08-30 19:13:21.955: e/androidruntime(7272): caused by: java.lang.nullpointerexception 08-30 19:13:21.955: e/androidruntime(7272): @ alesto.androidinterview.simplequestion.oncreate(simplequestion.java:56) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activity.performcreate(activity.java:5231) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) 08-30 19:13:21.955: e/androidruntime(7272): @ android.app.activitythread.performlaunchactivity(activitythread.java:2173) 08-30 19:13:21.955: e/androidruntime(7272): ... 11 more 08-30 19:13:21.965: v/activitythread(7272): schedule 102 pause_activity_finishing: 0 / android.os.binderproxy@429157e0 08-30 19:13:22.535: v/activitythread(7272): schedule 109 destroy_activity: 1 / android.os.binderproxy@428cbe18 08-30 19:13:22.535: v/activitythread(7272): schedule 140 trim_memory: 20 / null 08-30 19:13:22.535: v/activitythread(7272): schedule 109 destroy_activity: 1 / android.os.binderproxy@429157e0
here front page activity :
package alesto.androidinterview; import android.support.v7.app.actionbaractivity; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.linearlayout; import android.app.actionbar; import android.content.intent; import android.net.uri; import android.os.bundle; public class frontpage extends actionbaractivity implements onclicklistener { button bsimple, btough, bseeapps, brateapp; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.front_page); //initializing buttons bsimple = (button) findviewbyid(r.id.bsq); btough = (button) findviewbyid(r.id.btq); bseeapps = (button) findviewbyid(r.id.bseeotherapps); brateapp = (button) findviewbyid(r.id.brateapp); bsimple.setonclicklistener(this); btough.setonclicklistener(this); bseeapps.setonclicklistener(this); brateapp.setonclicklistener(this); //adding action bar linearlayout frontll = (linearlayout) findviewbyid(r.id.front_page_titlebar); getsupportactionbar().setdisplayoptions(actionbar.display_show_custom); getsupportactionbar().setcustomview(r.layout.front_page_title_bar); } @override public void onclick(view v) { // todo auto-generated method stub switch (v.getid()) { case r.id.bsq: intent = new intent(frontpage.this, simplequestion.class); startactivity(i); break; case r.id.btq: intent j = new intent(frontpage.this, toughquestion.class); startactivity(j); break; case r.id.bseeotherapps: break; case r.id.brateapp: uri uri1 = uri.parse("market://details?id="+getpackagename()); intent gotomarket1 = new intent(intent.action_view, uri1); startactivity(gotomarket1); break; } } }
and its' xml file:
<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="@drawable/bgfirst" android:id="@+id/frontpagelayout" > <button android:id="@+id/bsq" android:layout_width="200dp" android:layout_height="40dp" android:textsize="20sp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="32dp" android:background="@drawable/button_custom" android:textcolor="#050000" android:text="@string/sq" /> <button android:id="@+id/btq" android:layout_width="200dp" android:layout_height="40dp" android:textsize="20sp" android:layout_below="@id/bsq" android:layout_centerhorizontal="true" android:layout_margintop="44dp" android:background="@drawable/button_custom" android:textcolor="#050000" android:text="@string/tq" /> <button android:id="@+id/bseeotherapps" android:layout_width="250dp" android:layout_height="40dp" android:textsize="20sp" android:layout_below="@id/btq" android:layout_centerhorizontal="true" android:layout_margintop="50dp" android:background="@drawable/button_custom" android:textcolor="#050000" android:text="@string/soa" /> <button android:id="@+id/brateapp" android:layout_width="200dp" android:layout_height="40dp" android:textsize="20sp" android:layout_below="@id/bseeotherapps" android:layout_centerhorizontal="true" android:layout_margintop="49dp" android:background="@drawable/button_custom" android:textcolor="#050000" android:text="@string/ra" /> </relativelayout>
destination activity:
package alesto.androidinterview; import java.util.locale; import android.app.actionbar; import android.os.bundle; import android.speech.tts.texttospeech; import android.support.annotation.nullable; import android.support.v7.app.actionbaractivity; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.linearlayout; import android.widget.textview; import android.widget.toast; public class simplequestion extends actionbaractivity implements onclicklistener { textview tvquestion, tvanswer, tvtotallength, tvpresentindex; button bleft, bright, bshow; string[] simplequestions, simpleanswers; int index; public static final string defaultanswer = "press \"a\" answer"; // variables , object of text-to-speech texttospeech ttsobject; int result; @override protected void oncreate(@nullable bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.questions); // initializiation of textviews , buttons tvquestion = (textview) findviewbyid(r.id.tvquestion); tvanswer = (textview) findviewbyid(r.id.tvanswer); tvtotallength = (textview) findviewbyid(r.id.tvyy); tvpresentindex = (textview) findviewbyid(r.id.tvxx); bleft = (button) findviewbyid(r.id.bleft); bright = (button) findviewbyid(r.id.bright); bshow = (button) findviewbyid(r.id.bshowanswer); button bspeak = (button) findviewbyid(r.id.bspeak); button bstop = (button) findviewbyid(r.id.bstop_mute); // setting onclick listeners 3 buttons , speak/mute buttons bleft.setonclicklistener(this); bright.setonclicklistener(this); bshow.setonclicklistener(this); bspeak.setonclicklistener(this); bstop.setonclicklistener(this); // importing string arrays simplequestions = getresources().getstringarray(r.array.simple_ques); simpleanswers = getresources().getstringarray(r.array.simple_ans); // setting values different variables index = 0; tvquestion.settext(simplequestions[index]); tvanswer.settext(defaultanswer); tvpresentindex.settext(string.valueof(index + 1)); tvtotallength.settext("/" + string.valueof(simplequestions.length)); // adding action bar , customizing linearlayout questionll = (linearlayout) findviewbyid(r.id.question_page_titlebar); getsupportactionbar().setdisplayoptions(actionbar.display_show_custom); getsupportactionbar().setcustomview(r.layout.questions_title_bar); textview category = (textview) findviewbyid(r.id.tv_questions_titlebar); category.settext("simple questions"); // initialization of text-to-speech object ttsobject = new texttospeech(simplequestion.this, new texttospeech.oninitlistener() { @override public void oninit(int status) { // todo auto-generated method stub if (status == texttospeech.success) { ttsobject.setlanguage(locale.english); } else { toast.maketext(getapplicationcontext(), "feature not supported in device", toast.length_short).show(); } } }); } @override public void onclick(view v) { // todo auto-generated method stub switch (v.getid()) { case r.id.bleft: bshow.setactivated(false); tvanswer.settext(defaultanswer); index--; if (index == -1) { index = simplequestions.length - 1; } tvquestion.settext(simplequestions[index]); tvpresentindex.settext(string.valueof(index + 1)); break; case r.id.bright: bshow.setactivated(false); tvanswer.settext(defaultanswer); index++; if (index == simplequestions.length) { index = 0; } tvquestion.settext(simplequestions[index]); tvpresentindex.settext(string.valueof(index + 1)); break; case r.id.bshowanswer: tvanswer.settext(simpleanswers[index]); bshow.setactivated(true); break; case r.id.bspeak: if (result == texttospeech.lang_not_supported || result == texttospeech.lang_missing_data) { toast.maketext(getapplicationcontext(), "feature not supported in device", toast.length_short).show(); } else { if (!tvanswer.gettext().tostring().equals(defaultanswer)) { ttsobject.speak(simpleanswers[index], texttospeech.queue_flush, null); } } break; case r.id.bstop_mute: if (ttsobject != null) { ttsobject.stop(); } break; } } protected void ondestroy() { // todo auto-generated method stub super.ondestroy(); if (ttsobject != null) { ttsobject.stop(); ttsobject.shutdown(); } } }
destination xml file:
<?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" android:weightsum="100"> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="8" android:gravity="center" android:background="@drawable/bg_topbottom" > <textview android:id="@+id/tvxx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_xx" android:textcolor="#000000" /> <textview android:id="@+id/tvyy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_yy" android:textcolor="#000000" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="vertical" android:layout_weight="80" android:background="@drawable/main_background" > <textview android:id="@+id/tvquestion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="18dp" android:text="@string/tv_question" android:textcolor="#000000" /> <scrollview android:id="@+id/scrollview1" android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <textview android:id="@+id/tvanswer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="15dp" android:text="@string/tv_answer" android:textcolor="#000000" /> </linearlayout> </scrollview> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="12" android:gravity="center_horizontal|center" android:background="@drawable/bg_topbottom" > <button android:id="@+id/bleft" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/left_button" /> <button android:id="@+id/bshowanswer" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/a_button" /> <button android:id="@+id/bright" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/right_button" /> </linearlayout> </linearlayout>
tried clean function in eclipse. didn't unfortunately.
the underlying error specified in logcat:
08-30 19:13:21.955: e/androidruntime(7272): caused by: java.lang.nullpointerexception 08-30 19:13:21.955: e/androidruntime(7272): @ alesto.androidinterview.simplequestion.oncreate(simplequestion.java:56)
and line 56 is:
bspeak.setonclicklistener(this);
so bspeak
null. bspeak
initialized by
button bspeak = (button) findviewbyid(r.id.bspeak);
and means view not contain view id r.id.bspeak
. should either create missing view bspeak
or remove code referencing it.
Comments
Post a Comment