java - How to check if checkbox was checked? -


i creating quiz app androids. have 3 fragments , 3 checkboxes on first 2 of them. on last fragment there button when pressed opens activity called "end". need on "end" activity result appear of how many correct answers 1 have chosen.

firstly, i've tried check if it's working first fragment, got stuck. app closes when press button.

end.java:

       package bandymas.viewpagerexample;  import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.checkbox; import android.widget.textview;   public class end extends actionbaractivity {      private checkbox checkbox1, checkbox2, checkbox3;     private button button;     textview newresult = (textview)findviewbyid(r.id.textview1);       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_end);         getsupportactionbar().hide();          addlisteneronbutton();     }      private void addlisteneronbutton() {          checkbox1 = (checkbox) findviewbyid(r.id.checkbox1);         checkbox2 = (checkbox) findviewbyid(r.id.checkbox2);         checkbox3 = (checkbox) findviewbyid(r.id.checkbox3);         button = (button) findviewbyid(r.id.button);          button.setonclicklistener(new view.onclicklistener() {              //run when button clicked             @override             public void onclick(view v) {                  stringbuffer result = new stringbuffer();                 result.append("checkbox1 : ").append(checkbox1.ischecked());                 result.append("\ncheckbox2 : ").append(checkbox2.ischecked());                 result.append("\ncheckbox3 :").append(checkbox3.ischecked());                  newresult.settext("my awesome text");             }         });     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_naujas_baigimas, 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();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

here's logcat:

04-01 20:04:37.564    6020-6020/bandymas.viewpagerexample w/applicationpackagemanager﹕ getcscpackageitemtext() 04-01 20:04:37.564    6020-6020/bandymas.viewpagerexample i/personamanager﹕ getpersonaservice() name persona_policy 04-01 20:04:37.684    6020-6020/bandymas.viewpagerexample i/adreno-egl﹕ <qegldrvapi_eglinitialize:381>: egl 1.4 qualcomm build:  (cl3869936)     opengl es shader compiler version: 17.01.11.spl     build date: 01/17/14 fri     local branch:     remote branch:     local patches:     reconstruct branch: 04-01 20:04:37.734    6020-6020/bandymas.viewpagerexample d/openglrenderer﹕ enabling debug mode 0 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample i/selinux﹕ function: selinux_android_load_priority [0], there no sepolicy file. 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample i/selinux﹕ function: selinux_android_load_priority , priority version ve=sepf_gt-i9505_4.4.2_0033 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample i/selinux﹕ selinux_android_seapp_context_reload: seapp_contexts file loaded /seapp_contexts 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample e/dalvikvm﹕ >>>>> normal user 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample e/dalvikvm﹕ >>>>> bandymas.viewpagerexample [ userid:0 | appid:10229 ] 04-01 20:07:31.404    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ late-enabling checkjni 04-01 20:07:31.584    7094-7094/bandymas.viewpagerexample w/applicationpackagemanager﹕ getcscpackageitemtext() 04-01 20:07:31.594    7094-7094/bandymas.viewpagerexample i/personamanager﹕ getpersonaservice() name persona_policy 04-01 20:07:31.794    7094-7094/bandymas.viewpagerexample i/adreno-egl﹕ <qegldrvapi_eglinitialize:381>: egl 1.4 qualcomm build:  (cl3869936)     opengl es shader compiler version: 17.01.11.spl     build date: 01/17/14 fri     local branch:     remote branch:     local patches:     reconstruct branch: 04-01 20:07:31.844    7094-7094/bandymas.viewpagerexample d/openglrenderer﹕ enabling debug mode 0 04-01 20:07:42.454    7094-7094/bandymas.viewpagerexample w/applicationpackagemanager﹕ getcscpackageitemtext() 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample i/dalvikvm﹕ not find method android.view.viewgroup.onnestedscrollaccepted, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.onnestedscrollaccepted 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ vfy: unable resolve virtual method 11347: landroid/view/viewgroup;.onnestedscrollaccepted (landroid/view/view;landroid/view/view;i)v 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ vfy: replacing opcode 0x6f @ 0x0000 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample i/dalvikvm﹕ not find method android.view.viewgroup.onstopnestedscroll, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.onstopnestedscroll 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ vfy: unable resolve virtual method 11353: landroid/view/viewgroup;.onstopnestedscroll (landroid/view/view;)v 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ vfy: replacing opcode 0x6f @ 0x0000 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample i/dalvikvm﹕ not find method android.support.v7.internal.widget.actionbaroverlaylayout.stopnestedscroll, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.sethideoncontentscrollenabled 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ vfy: unable resolve virtual method 9041: landroid/support/v7/internal/widget/actionbaroverlaylayout;.stopnestedscroll ()v 04-01 20:07:42.485    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x000e 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample i/dalvikvm﹕ not find method android.content.res.typedarray.getchangingconfigurations, referenced method android.support.v7.internal.widget.tinttypedarray.getchangingconfigurations 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ vfy: unable resolve virtual method 365: landroid/content/res/typedarray;.getchangingconfigurations ()i 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample i/dalvikvm﹕ not find method android.content.res.typedarray.gettype, referenced method android.support.v7.internal.widget.tinttypedarray.gettype 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ vfy: unable resolve virtual method 387: landroid/content/res/typedarray;.gettype (i)i 04-01 20:07:42.495    7094-7094/bandymas.viewpagerexample d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 04-01 20:07:42.525    7094-7094/bandymas.viewpagerexample d/androidruntime﹕ shutting down vm 04-01 20:07:42.525    7094-7094/bandymas.viewpagerexample w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x4187fda0) 04-01 20:07:42.525    7094-7094/bandymas.viewpagerexample e/androidruntime﹕ fatal exception: main     process: bandymas.viewpagerexample, pid: 7094     java.lang.runtimeexception: unable start activity componentinfo{bandymas.viewpagerexample/bandymas.viewpagerexample.end}: java.lang.nullpointerexception             @ android.app.activitythread.performlaunchactivity(activitythread.java:2305)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2363)             @ android.app.activitythread.access$900(activitythread.java:161)             @ android.app.activitythread$h.handlemessage(activitythread.java:1265)             @ android.os.handler.dispatchmessage(handler.java:102)             @ android.os.looper.loop(looper.java:157)             @ android.app.activitythread.main(activitythread.java:5356)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1081)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nullpointerexception             @ bandymas.viewpagerexample.end.addlisteneronbutton(end.java:33)             @ bandymas.viewpagerexample.end.oncreate(end.java:23)             @ android.app.activity.performcreate(activity.java:5426)             @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1105)             @ android.app.activitythread.performlaunchactivity(activitythread.java:2269)             at android.app.activitythread.handlelaunchactivity(activitythread.java:2363)             at android.app.activitythread.access$900(activitythread.java:161)             at android.app.activitythread$h.handlemessage(activitythread.java:1265)             at android.os.handler.dispatchmessage(handler.java:102)             at android.os.looper.loop(looper.java:157)             at android.app.activitythread.main(activitythread.java:5356)             at java.lang.reflect.method.invokenative(native method)             at java.lang.reflect.method.invoke(method.java:515)             at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:1081)             at dalvik.system.nativestart.main(native method) 

activity_end.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:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     tools:context="bandymas.viewpagerexample.end">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancemedium"         android:text="result"         android:id="@+id/textview1"         android:layout_margintop="100dp"         android:textsize="40dp"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true" />  </relativelayout> 

please check there button(r.id.button) in activity_end.xml.

i guess button's id doesn't exist in activity_end.xml.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -