android - Unfortunately, (my app name) has stopped -


this question has answer here:

i new android app development , using eclipse. created 2 activities , added button main activity suppose open blank second activity. app keeps stopping when try to run on phone.

this logcat in eclipse:

04-14 21:16:07.373: e/trace(27640): error opening trace file: no such file   or directory (2)  04-14 21:16:07.603: e/androidruntime(27640): fatal exception: main 04-14 21:16:07.603: e/androidruntime(27640): java.lang.runtimeexception: unable start activity componentinfo{com.example.inveslator/com.example.inveslator.mainactivity}: java.lang.nullpointerexception 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2071) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2096) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread.access$600(activitythread.java:138) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread$h.handlemessage(activitythread.java:1207) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.os.handler.dispatchmessage(handler.java:99) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.os.looper.loop(looper.java:213) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread.main(activitythread.java:4787) 04-14 21:16:07.603: e/androidruntime(27640):    @ java.lang.reflect.method.invokenative(native method) 04-14 21:16:07.603: e/androidruntime(27640):    @ java.lang.reflect.method.invoke(method.java:511) 04-14 21:16:07.603: e/androidruntime(27640):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:789) 04-14 21:16:07.603: e/androidruntime(27640):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:556) 04-14 21:16:07.603: e/androidruntime(27640):    @ dalvik.system.nativestart.main(native method) 04-14 21:16:07.603: e/androidruntime(27640): caused by: java.lang.nullpointerexception 04-14 21:16:07.603: e/androidruntime(27640):    @ com.example.inveslator.mainactivity.oncreate(mainactivity.java:21) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activity.performcreate(activity.java:5008) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 04-14 21:16:07.603: e/androidruntime(27640):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2035) 04-14 21:16:07.603: e/androidruntime(27640):    ... 11 more 

below androidmanifest.xml:

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

and mainactivity.java:

package com.example.inveslator;  import android.content.intent; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.view.onclicklistener; import android.widget.button;   public class mainactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button b = (button) findviewbyid(android.r.id.button1);         b.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 startactivity(new intent(mainactivity.this, second.class));              }         });     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();         if (id == r.id.action_settings) {             return true;         }         return super.onoptionsitemselected(item);     } }  glad know whats wrong. in advance 

i assume it's line

button b = (button) findviewbyid(android.r.id.button1); 

i guess have button id = button1 in xml layout. in case use:

button b = (button) findviewbyid(r.id.button1); 

android.r sdk resources , r.id.some_id ids create


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -