Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use the if statement with radiobuttons
    primarykey
    data
    text
    <p>i would like to start a new activity according to the radiobutton that the user choose.this is my non working code(i m using a toast message for now instead of a new activity)</p> <pre><code>public class cafechoice extends Activity { /** Called when the activity is first created. */ public RadioButton rb1; public RadioButton rb2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.cafechoice); final RadioButton rb1 = (RadioButton) findViewById(R.id.radio_red); final RadioButton rb2 = (RadioButton) findViewById(R.id.radio_blue); rb1.setOnClickListener(radio_listener); rb2.setOnClickListener(radio_listener); } OnClickListener radio_listener = new OnClickListener() { public void onClick(View v) { // Perform action on clicks if(v == radio_listener) { if(rb1.isChecked() == true){Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();} if(rb2.isChecked() == true){Toast.makeText(cafechoice.this, 1, Toast.LENGTH_SHORT).show();} } } }; } </code></pre> <p>@rekaszeru this is my logcatview</p> <pre><code>05-02 17:16:28.206: WARN/dalvikvm(678): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 05-02 17:16:28.216: ERROR/AndroidRuntime(678): Uncaught handler: thread main exiting due to uncaught exception 05-02 17:16:28.248: ERROR/AndroidRuntime(678): java.lang.RuntimeException: Unable to start activity ComponentInfo{kostas.menu.chania/kostas.menu.chania.cafechoice}: java.lang.NullPointerException 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.os.Handler.dispatchMessage(Handler.java:99) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.os.Looper.loop(Looper.java:123) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread.main(ActivityThread.java:4338) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at java.lang.reflect.Method.invokeNative(Native Method) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at java.lang.reflect.Method.invoke(Method.java:521) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at dalvik.system.NativeStart.main(Native Method) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): Caused by: java.lang.NullPointerException 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at kostas.menu.chania.cafechoice.onCreate(cafechoice.java:24) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444) 05-02 17:16:28.248: ERROR/AndroidRuntime(678): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload