Android error : java.lang.NullPointerException: Attempt to invoke virtual method -


trying go next activity on button click.also data passed intent.i have error in android :

08-18 07:03:52.979 10587-10587/? e/androidruntime: fatal exception: main process: com.example.anjana.crmapp, pid: 10587 java.lang.runtimeexception: unable start activity componentinfo{com.example.anjana.crmapp/com.example.anjana.crmapp.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'android.view.view android.widget.button.findviewbyid(int)' on null object reference @ android.app.activitythread.performlaunchactivity(activitythread.java:2416) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2476) @ android.app.activitythread.-wrap11(activitythread.java) @ android.app.activitythread$h.handlemessage(activitythread.java:1344) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.view.view android.widget.button.findviewbyid(int)' on null object reference @ com.example.anjana.crmapp.mainactivity.oncreate(mainactivity.java:24) @ android.app.activity.performcreate(activity.java:6237) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1107) @ android.app.activitythread.performlaunchactivity(activitythread.java:2369) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2476)  @ android.app.activitythread.-wrap11(activitythread.java)  @ android.app.activitythread$h.handlemessage(activitythread.java:1344)  @ android.os.handler.dispatchmessage(handler.java:102)  @ android.os.looper.loop(looper.java:148)  @ android.app.activitythread.main(activitythread.java:5417)  @ java.lang.reflect.method.invoke(native method)  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726)  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)

mainactivity.java :

package com.example.anjana.crmapp;  import android.app.activity; import android.content.intent; import android.provider.contactscontract; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.imagebutton;  public class mainactivity extends activity {      button btnyes, btnno;     imagebutton btngood,btnavg,btnpoor;      int ans;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          btnyes = (button) btnyes.findviewbyid(r.id.btnyes);         btnno = (button) btnno.findviewbyid(r.id.btnno);         btngood=(imagebutton) btngood.findviewbyid(r.id.btngood);         btnavg=(imagebutton) btnavg.findviewbyid(r.id.btnavg);         btnpoor=(imagebutton) btnpoor.findviewbyid(r.id.btnpoor);          btngood.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  ans=1;              }         });         btnavg.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  ans=2;              }         });         btnpoor.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  ans=3;              }         });          btnyes.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  //intent yesintent=new intent();                 //yesintent.putextra("ans",ans);                 //startactivity(yesintent);              }         });          btnno.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  intent nointent=new intent(getapplicationcontext(),contact.class);                 nointent.putextra("ans",ans);                 startactivity(nointent);              }         });      } } 

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.anjana.crmapp.mainactivity"     android:weightsum="1">      <textview         android:id="@+id/textview"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margintop="37dp"         android:layout_weight="0.25"         android:fontfamily="sans-serif"         android:text="rate overall experience \n our service"         android:textalignment="center"         android:textcolor="@color/colorprimarydark"         android:textsize="24sp"         android:textstyle="bold"         app:layout_constraintbottom_tobottomof="parent"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_totopof="parent"         android:layout_alignparenttop="true"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true" />      <imagebutton         android:id="@+id/btngood"         android:layout_width="125dp"         android:layout_height="100dp"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_below="@+id/textview"         android:layout_marginleft="17dp"         android:layout_marginstart="17dp"         android:layout_margintop="48dp"         app:srccompat="@drawable/good" />      <imagebutton         android:id="@+id/btnavg"         android:layout_width="125dp"         android:layout_height="100dp"         android:layout_alignbottom="@+id/btngood"         android:layout_centerhorizontal="true"         app:srccompat="@drawable/average" />      <imagebutton         android:id="@+id/btnpoor"         android:layout_width="125dp"         android:layout_height="100dp"         android:layout_alignparentend="true"         android:layout_alignparentright="true"         android:layout_aligntop="@+id/btnavg"         android:layout_marginend="20dp"         android:layout_marginright="20dp"         app:srccompat="@drawable/poor" />      <textview         android:id="@+id/textview3"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margintop="24dp"         android:fontfamily="sans-serif"         android:text="good"         android:textcolor="@android:color/background_dark"         android:textsize="18sp"         android:textstyle="bold"         android:layout_below="@+id/btngood"         android:layout_alignleft="@+id/btngood"         android:layout_alignstart="@+id/btngood"         android:layout_marginleft="27dp"         android:layout_marginstart="27dp" />      <textview         android:id="@+id/textview4"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/textview3"         android:layout_alignbottom="@+id/textview3"         android:layout_centerhorizontal="true"         android:fontfamily="sans-serif"         android:text="average"         android:textcolor="@android:color/background_dark"         android:textsize="18sp"         android:textstyle="bold" />      <textview         android:id="@+id/textview5"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentend="true"         android:layout_alignparentright="true"         android:layout_aligntop="@+id/textview4"         android:layout_marginend="32dp"         android:layout_marginright="32dp"         android:fontfamily="sans-serif"         android:text="poor"         android:textcolor="@android:color/background_dark"         android:textsize="18sp"         android:textstyle="bold" />      <textview         android:id="@+id/textview7"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="take part in our feedback survey.."         android:textalignment="center"         android:textcolor="@color/colorprimarydark"         android:textsize="22dp"         android:textstyle="bold"         android:layout_alignbottom="@+id/textview5"         android:layout_alignleft="@+id/textview3"         android:layout_alignstart="@+id/textview3" />      <button         android:id="@+id/btnyes"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="yes"         android:layout_marginbottom="76dp"         android:layout_alignparentbottom="true"         android:layout_torightof="@+id/btnavg"         android:layout_toendof="@+id/btnavg" />      <button         android:id="@+id/btnno"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_aligntop="@+id/btnyes"         android:layout_toendof="@+id/textview3"         android:layout_torightof="@+id/textview3"         android:text="no,thanks" />   </relativelayout> 

i don't know why error occurs!please me...


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -