android - App is Force Closing but I can't figure out why -


i can't emulator working on slow computer have go through process of loading app physical device. compiles fine , can't notice obvious error doesn't want run. started happening after followed tutorial on how go page another. looks in comparison tutorial.

manifest file

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.mcesfireassist"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="10"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" android:hardwareaccelerated="false">         <activity             android:name="com.example.mcesfireassist.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:label="@string/app_name"                 android:name=".app2activity" >             </activity>    </application>  </manifest> 

main 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:background="@layout/activity_main"     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=".mainactivity" >      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/home_intro" />      <edittext         android:id="@+id/edittext1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/textview1"         android:layout_centerhorizontal="true"         android:layout_margintop="54dp"         android:ems="10"         android:inputtype="number"         android:singleline="true"         android:text="@string/unit_num" >          <requestfocus />     </edittext>      <edittext         android:id="@+id/edittext2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centervertical="true"         android:ems="10"         android:inputtype="textnosuggestions|textshortmessage"         android:text="@string/asn" />      <button         android:id="@+id/button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/edittext2"         android:layout_centerhorizontal="true"         android:layout_margintop="38dp"         android:text="@string/start_button" />  </relativelayout> 

main java file

package com.example.mcesfireassist;  import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button;  public class mainactivity extends activity {     button button;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;          }       public void addlisteneronbutton() {         final context context = this;         button = (button) findviewbyid (r.id.button1);         button.setonclicklistener(new onclicklistener() {             @override             public void onclick(view arg0) {                  intent intent = new intent(context, app2activity.class);                             startactivity(intent);             }         });  }  } 

if see java , xml of second page can add it, didn't wanna make post longer necessary.

you code not functioning because never call addlisteneronbutton() method. onclicklistener never attached button. in fact, reference button doesn't exist in activity.

you can either call addlisteneronbutton() after setcontentview(r.layout.activity_main) or try following code includes few changes:

package com.example.mcesfireassist;  import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button;  public class mainactivity extends activity {     button button;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button = (button) findviewbyid (r.id.button1);         button.setonclicklistener(new onclicklistener() {             @override             public void onclick(view arg0) {                  intent intent = new intent(mainactivity.this, app2activity.class);                 startactivity(intent);                 }         });     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;      }  } 

edit 1:

please change following code:

<activity     android:label="@string/app_name"     android:name=".app2activity" > </activity> 

to:

<activity     android:label="@string/app_name"     android:name="com.example.mcesfireassist.app2activity" > </activity>     

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -