java - How to fix the Force Close error? -
i trying create application if button clicked, new activity shown. keeping force close message , nothing comes handy. can do?
here java code:
package com.example.basic2; import android.content.intent; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; public class mainactivity extends actionbaractivity { public button mybtn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mybtn = (button) findviewbyid(r.id.button1); mybtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent intent = new intent(mainactivity.this, activity2.class); startactivity(intent); } }); } }
here xml code:
<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" tools:context="com.example.basic2.mainactivity$placeholderfragment" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview1" android:layout_centerhorizontal="true" android:layout_margintop="82dp" android:text="button" /> </relativelayout>
someone might have solution?
the errors given logcat is: http://prntscr.com/38xjpo
it's hard tell screenshot of logcat, looks mybtn null , throws nullpointerexception when try set onclicklistener. can check it?
the exception coming line 21 in source file.
Comments
Post a Comment