java - my app crashes before it starts.This is a simple app in which i am making the use of intent to call another class from a previous class -


intenttest.java:

    package intenttest.xyz.com;       import android.app.activity;    import android.content.intent;    import android.os.bundle;   import android.view.view;   import android.widget.button;        public class intenttest extends activity {       button b;             /** called when activity first created. */      @override       public void oncreate(bundle savedinstancestate) {        super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          b = (button) findviewbyid(r.id.b);          b.setonclicklistener( new view.onclicklistener() {            public void onclick(view view) {             intent intent = new intent(intenttest.this,seond.class );             startactivity(intent);             }         });      } } 

main.xml:

 <?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"   >    <textview          android:layout_width="fill_parent"        android:layout_height="wrap_content"         android:text="first screen"       />     <button       android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="click"      android:name="@+id/b"      />     </linearlayout> 

seond.java:

package intenttest.xyz.com;  import android.app.activity; import android.os.bundle;  public class seond extends activity{     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.second);       }  } 

second.xml:

 <?xml version="1.0" encoding="utf-8"?>  <linearlayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:layout_width="wrap_content"   android:layout_height="wrap_content">       <textview       android:layout_width="fill_parent"      android:layout_height="wrap_content"     android:text="second screen"      /> 

manifest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"   package="intenttest.xyz.com"   android:versioncode="1"   android:versionname="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name">     <activity android:name=".intenttest"               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=".seond"></activity> </application>   </manifest>  

i following error code:

11-16 01:26:07.156: error/androidruntime(779): uncaught handler: thread main exiting  due uncaught exception 11-16 01:26:07.166: error/androidruntime(779): java.lang.runtimeexception: unable start activity componentinfo{intenttest.xyz.com/intenttest.xyz.com.intenttest}: java.lang.nullpointerexception 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2401) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2417) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread.access$2100(activitythread.java:116) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread$h.handlemessage(activitythread.java:1794) 11-16 01:26:07.166: error/androidruntime(779):     @ android.os.handler.dispatchmessage(handler.java:99) 11-16 01:26:07.166: error/androidruntime(779):     @ android.os.looper.loop(looper.java:123) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread.main(activitythread.java:4203) 11-16 01:26:07.166: error/androidruntime(779):     @ java.lang.reflect.method.invokenative(native method) 11-16 01:26:07.166: error/androidruntime(779):     @ java.lang.reflect.method.invoke(method.java:521) 11-16 01:26:07.166: error/androidruntime(779):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 11-16 01:26:07.166: error/androidruntime(779):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:549) 11-16 01:26:07.166: error/androidruntime(779):     @ dalvik.system.nativestart.main(native method) 11-16 01:26:07.166: error/androidruntime(779): caused by: java.lang.nullpointerexception 11-16 01:26:07.166: error/androidruntime(779):     @ intenttest.xyz.com.intenttest.oncreate(intenttest.java:18) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1123) 11-16 01:26:07.166: error/androidruntime(779):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2364) 11-16 01:26:07.166: error/androidruntime(779):     ... 11 more 

look @ main.xml file, have made little mistake leads lot of discussion sometimes.

android:name="@+id/b"

it should like:

android:id="@+id/b"

so can access element in activity , that's why application causing

nullpointerexception  

by way using small letters in class name , capital letters in package name not practice coders.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -