java - Getting Null point exception when Clicking Button(Android) -


i'm getting null point exception whenever click aws button in front page, have brained stormed alot, i'm not able understand why. m going paste few lines of code relevant, please @ it, , let me know m going wrong. thanks

manifest file

     <activity         android:name=".front"         android:label="@string/title_activity_front" >         <intent-filter>             <action android:name="com.example.getit.front" />              <category android:name="android.intent.category.default" />         </intent-filter>     </activity>    <activity         android:name=".awsstartact"         android:label="@string/title_activity_aws_start" >         <intent-filter>             <action android:name="com.example.getit.awsstartact" />              <category android:name="android.intent.category.default" />         </intent-filter>     </activity> 

front.class

   public class front extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_front);     //declaring buttons     button baws = (button) findviewbyid(r.id.baws);     button bazure = (button) findviewbyid(r.id.bmazure);     button bhadoop = (button) findviewbyid(r.id.bhadoop);     //creating on click listeners     //for aws     baws.setonclicklistener(new view.onclicklistener() {          @override         //this have things button compute on click         public void onclick(view v) {             // todo auto-generated method stub             //go aws option page              intent intent= new intent(front.this,awsstartact.class);             startactivity(intent);         }     });     //for azure     bazure.setonclicklistener(new view.onclicklistener() {          @override         //this have things button compute on click         public void onclick(view v) {             // todo auto-generated method stub             //go azure option page             intent intent= new intent(front.this,azurestart.class);             startactivity(intent);         }     });     //for hadoop     bhadoop.setonclicklistener(new view.onclicklistener() {  @override //this have things button compute on click public void onclick(view v) {     // todo auto-generated method stub  }  }); }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.front, 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);     }  } 

awsstartact.class

  public class awsstartact extends actionbaractivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_aws_start);     //declaring buttons , linking xml button id     button compute, storage, database;     compute=(button) findviewbyid (r.id.bcompute);     storage=(button) findviewbyid (r.id.bstorage);     database=(button) findviewbyid (r.id.bhadoop);     //defining onclick listener each button     //compute     compute.setonclicklistener(new view.onclicklistener() {          @override         //this have things button compute on click         public void onclick(view v) {             // todo auto-generated method stub             //going compute page             intent intent = new intent(awsstartact.this,awscompute.class);             startactivity(intent);         }     });     //storage     storage.setonclicklistener(new view.onclicklistener() {          @override         //this have things button compute on click         public void onclick(view v) {             // todo auto-generated method stub          }     });     //database     database.setonclicklistener(new view.onclicklistener() {          @override         //this have things button compute on click         public void onclick(view v) {             // todo auto-generated method stub          }     }); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.aws_start, 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); }  } 

activity xml layout

   <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.getit.front" android:background="#555" >   <button     android:id="@+id/baws"     android:layout_width="250dp"     android:layout_height="wrap_content"     android:layout_alignparenttop="true"     android:layout_centerhorizontal="true"     android:layout_margintop="132dp"     android:text="aws" />  <button     android:id="@+id/bmazure"     android:layout_width="250dp"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/baws"     android:layout_below="@+id/baws"     android:layout_margintop="33dp"     android:text="microsoft azure" />  <button     android:id="@+id/bhadoop"     android:layout_width="250dp"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/bmazure"     android:layout_below="@+id/bmazure"     android:layout_margintop="33dp"     android:text="hadoop" />  <textview     android:id="@+id/twelcome"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:layout_margintop="26dp"     android:gravity="center"     android:text="@string/ref"     android:textcolor="#fff"     android:textsize="20sp" />  <textview     android:id="@+id/fronttext"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/twelcome"     android:layout_centerhorizontal="true"     android:textsize="18dp"     android:layout_margintop="16dp"     android:text="choose service provider"     android:textappearance="?android:attr/textappearancelarge"     android:textcolor="#fff" />    </relativelayout> 

aws click layout

 <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.getit.awsstartact"  android:background="#555" >   <textview     android:id="@+id/tchoose"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/twelcome"     android:layout_centerhorizontal="true"     android:layout_margintop="11dp"     android:text="choose type of service want"     android:textcolor="#fff"     android:textsize="18sp" />  <button     android:id="@+id/bcompute"     android:layout_width="250sp"     android:layout_height="wrap_content"     android:layout_below="@+id/tchoose"     android:layout_centerhorizontal="true"     android:layout_margintop="18dp"     android:gravity="center"     android:text="compute" />  <button     android:id="@+id/bstorage"     android:layout_width="250dp"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/bcompute"     android:layout_below="@+id/bcompute"     android:layout_margintop="41dp"     android:text="storage" />  <button     android:id="@+id/bdatabase"     android:layout_width="250dp"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/bstorage"     android:layout_below="@+id/bstorage"     android:layout_margintop="37dp"     android:text="database" />      </relativelayout> 

stack trace

07-23 22:09:28.518: e/androidruntime(361): fatal exception: main 07-23 22:09:28.518: e/androidruntime(361): java.lang.runtimeexception:    unable start activity      componentinfo{com.example.getit/com.example.getit.awsstartact}:    java.lang.nullpointerexception 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1647) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread.access$1500(activitythread.java:117) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread$h.handlemessage(activitythread.java:931) 07-23 22:09:28.518: e/androidruntime(361):  @ android.os.handler.dispatchmessage(handler.java:99) 07-23 22:09:28.518: e/androidruntime(361):  @ android.os.looper.loop(looper.java:123) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread.main(activitythread.java:3683) 07-23 22:09:28.518: e/androidruntime(361):  @ java.lang.reflect.method.invokenative(native method) 07-23 22:09:28.518: e/androidruntime(361):  @ java.lang.reflect.method.invoke(method.java:507) 07-23 22:09:28.518: e/androidruntime(361):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 07-23 22:09:28.518: e/androidruntime(361):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 07-23 22:09:28.518: e/androidruntime(361):  @ dalvik.system.nativestart.main(native method) 07-23 22:09:28.518: e/androidruntime(361): caused by: java.lang.nullpointerexception 07-23 22:09:28.518: e/androidruntime(361):  @ com.example.getit.awsstartact.oncreate(awsstartact.java:46) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 07-23 22:09:28.518: e/androidruntime(361):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1611) 07-23 22:09:28.518: e/androidruntime(361):  ... 11 more 

in awsstartact oncreate() you're using wrong id bhadoop button database. it's not in layout, findviewbyid() cannot find , returns null.

this issue:

database=(button) findviewbyid (r.id.bhadoop); 

most should be:

r.id.bdatabase 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -