Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing from one intent to another
    primarykey
    data
    text
    <p>i have one button n 6 radio buttons in activity. after getting input from edit text on click of button(search) it goes to another activity. below is my code</p> <pre><code>public void search(View v) { switch(v.getId()) { case R.id.button1: EditText et1= (EditText)findViewById(R.id.editText1); RadioButton r1 = (RadioButton) findViewById(R.id.radio0); RadioButton r2 = (RadioButton) findViewById(R.id.radio1); RadioButton r3 = (RadioButton) findViewById(R.id.radio2); RadioButton r4 = (RadioButton) findViewById(R.id.radio3); RadioButton r5 = (RadioButton) findViewById(R.id.radio4); RadioButton r6 = (RadioButton) findViewById(R.id.radio5); pin=et1.getText().toString(); if(pin.length()==0){ Toast.makeText(this, "Please provide Input!", Toast.LENGTH_SHORT).show(); return; } if(r1.isChecked()) { category="All"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r2.isChecked()) { category="Food"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r3.isChecked()) { category="Entertainment"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r4.isChecked()) { category="Shopping"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r5.isChecked()) { category="Health"; Intent i=new Intent(this,Details.class); startActivity(i); } else if (r6.isChecked()) { category="Services"; Intent i=new Intent(this,Details.class); startActivity(i); } break; } /*if(pin.length()!=0&amp;&amp;category.length()!=0) { Intent i=new Intent(this,Details.class); startActivity(i); }*/ } </code></pre> <p>is the above code correct?? while running force close happens when input given .but when no input the toast msg is displayed.</p> <p>the log cat is </p> <pre><code>09-29 23:56:25.706: E/AndroidRuntime(23196): FATAL EXCEPTION: main 09-29 23:56:25.706: E/AndroidRuntime(23196): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yellowpages/com.yellowpages.Details}: java.lang.NullPointerException 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread.access$600(ActivityThread.java:123) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.os.Handler.dispatchMessage(Handler.java:99) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.os.Looper.loop(Looper.java:137) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread.main(ActivityThread.java:4424) 09-29 23:56:25.706: E/AndroidRuntime(23196): at java.lang.reflect.Method.invokeNative(Native Method) 09-29 23:56:25.706: E/AndroidRuntime(23196): at java.lang.reflect.Method.invoke(Method.java:511) 09-29 23:56:25.706: E/AndroidRuntime(23196): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 09-29 23:56:25.706: E/AndroidRuntime(23196): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 09-29 23:56:25.706: E/AndroidRuntime(23196): at dalvik.system.NativeStart.main(Native Method) 09-29 23:56:25.706: E/AndroidRuntime(23196): Caused by: java.lang.NullPointerException 09-29 23:56:25.706: E/AndroidRuntime(23196): at com.yellowpages.Dbpages.fetchRecord(Dbpages.java:109) 09-29 23:56:25.706: E/AndroidRuntime(23196): at com.yellowpages.Details.onCreate(Details.java:22) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.Activity.performCreate(Activity.java:4465) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 09-29 23:56:25.706: E/AndroidRuntime(23196): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 09-29 23:56:25.706: E/AndroidRuntime(23196): ... 11 more package com.yellowpages; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Toast; public class UserSearch extends Activity { public static String category="",pin=""; @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_search); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_user_search, menu); return true; } public void search(View v) { switch(v.getId()) { case R.id.button1: EditText et1= (EditText)findViewById(R.id.editText1); RadioButton r1 = (RadioButton) findViewById(R.id.radio0); RadioButton r2 = (RadioButton) findViewById(R.id.radio1); RadioButton r3 = (RadioButton) findViewById(R.id.radio2); RadioButton r4 = (RadioButton) findViewById(R.id.radio3); RadioButton r5 = (RadioButton) findViewById(R.id.radio4); RadioButton r6 = (RadioButton) findViewById(R.id.radio5); pin=et1.getText().toString(); if(pin.length()==0){ Toast.makeText(this, "Please provide Input!", Toast.LENGTH_SHORT).show(); return; } if(r1.isChecked()) { category="All"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r2.isChecked()) { category="Food"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r3.isChecked()) { category="Entertainment"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r4.isChecked()) { category="Shopping"; Intent i=new Intent(this,Details.class); startActivity(i); } else if(r5.isChecked()) { category="Health"; Intent i=new Intent(this,Details.class); startActivity(i); } else if (r6.isChecked()) { category="Services"; Intent i=new Intent(this,Details.class); startActivity(i); } break; } /*if(pin.length()!=0&amp;&amp;category.length()!=0) { Intent i=new Intent(this,Details.class); startActivity(i); }*/ } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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