Note that there are some explanatory texts on larger screens.

plurals
  1. PONot passing text through activites in android
    primarykey
    data
    text
    <p>I am trying to get the text from one activity (Second.class) and pass it to another activity(Third.class). The string im trying to get is a TextView of an airport code.</p> <p>This is the piece of code i think that is causing the problem </p> <pre><code> this.btnD.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(context, Thrid.class); tvTemp = (TextView)findViewById(R.id.tvReturn); Bundle tb = new Bundle(); String d = tvTemp.getText().toString(); tb.putString("destenation", d); intent.putExtra("basket", tb); startActivity(intent); } }); </code></pre> <p>And my third class </p> <pre><code> destenationV=(TextView)findViewById(R.id.tvDes); Intent i = getIntent();//MAking an intent called i Bundle basket = i.getBundleExtra("basket"); String desTv = basket.getString("destenation"); if(desTv.toString() == "SNN (IRL)"){ desTv = "IRELAND"; destenationV.append(desTv); } else if(desTv.toString()=="EWR (USA)"){ desTv = "UNITED STATES"; destenationV.append(desTv); } else if(desTv.toString()=="LHR (GRB))"){ desTv ="UNITED KINGDOM"; destenationV.append(desTv); } </code></pre> <p>This is my Log Cat when i run my app</p> <pre><code>04-30 18:19:02.222: E/Trace(1102): error opening trace file: No such file or directory (2) 04-30 18:19:03.082: D/gralloc_goldfish(1102): Emulator without GPU emulation detected. 04-30 18:19:28.912: D/dalvikvm(1102): GC_CONCURRENT freed 123K, 3% free 8295K/8519K, paused 79ms+100ms, total 290ms 04-30 18:19:31.622: D/AndroidRuntime(1102): Shutting down VM 04-30 18:19:31.642: W/dalvikvm(1102): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 04-30 18:19:31.652: E/AndroidRuntime(1102): FATAL EXCEPTION: main 04-30 18:19:31.652: E/AndroidRuntime(1102): java.lang.NullPointerException 04-30 18:19:31.652: E/AndroidRuntime(1102): at com.example.assignment2.Second$3.onClick(Second.java:115) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.view.View.performClick(View.java:4084) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.view.View$PerformClick.run(View.java:16966) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.os.Handler.handleCallback(Handler.java:615) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.os.Handler.dispatchMessage(Handler.java:92) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.os.Looper.loop(Looper.java:137) 04-30 18:19:31.652: E/AndroidRuntime(1102): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-30 18:19:31.652: E/AndroidRuntime(1102): at java.lang.reflect.Method.invokeNative(Native Method) 04-30 18:19:31.652: E/AndroidRuntime(1102): at java.lang.reflect.Method.invoke(Method.java:511) 04-30 18:19:31.652: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-30 18:19:31.652: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-30 18:19:31.652: E/AndroidRuntime(1102): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Eclipse shows no errors(other then in logCat). Thanks in advance</p> <p>My complete Second class</p> <pre><code> public class Second extends Activity { private TextView typeTv, departureTv,returnTv,departureDateTv,returnDateTv,noOfPassengersTv,tvReturnDateLbl, tvTemp; private RadioButton buttonR = null; private CheckBox cCB; private Button btnD, btnB; final Context context = this; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); typeTv = (TextView)findViewById(R.id.typeTv); departureTv = (TextView)findViewById(R.id.departureTv); returnTv = (TextView)findViewById(R.id.returnTv); departureDateTv= (TextView)findViewById(R.id.departureDateTv); returnDateTv= (TextView)findViewById(R.id.returneDateTv); noOfPassengersTv = (TextView)findViewById(R.id.noOfPassengersTv); buttonR = (RadioButton) findViewById(R.id.radioR); tvReturnDateLbl = (TextView)findViewById(R.id.tvReturnDateLbl); cCB = (CheckBox)findViewById(R.id.correctCB); btnD= (Button)findViewById(R.id.btnDecsion); btnB= (Button)findViewById(R.id.btnBack); Intent i = getIntent();//MAking an intent called i Bundle basket = i.getBundleExtra("basket"); String tTv = basket.getString("type"); String dTv = basket.getString("departureAir"); String rTv = basket.getString("destenationAir"); String dDTv = basket.getString("depDate"); int nOPTv = basket.getInt("numOfPass"); String rDTv = basket.getString("returnDate"); if(rDTv == ""||rDTv==null){ returnDateTv.setVisibility(View.GONE); tvReturnDateLbl.setVisibility(View.GONE); } else{ returnDateTv.setText(rDTv); } cCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ btnD.setEnabled(true); } else{ btnD.setEnabled(false); } } }); typeTv.setText(tTv); departureTv.setText(dTv); returnTv.setText(rTv); departureDateTv.setText(dDTv); noOfPassengersTv.setText(""+nOPTv); this.btnB.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(context, MainActivity.class); startActivity(intent); } }); this.btnD.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(context, Thrid.class); tvTemp = (TextView)findViewById(R.id.tvReturn); Bundle tb = new Bundle(); String d = tvTemp.getText().toString(); tb.putString("destenation", d); intent.putExtra("basket", tb); startActivity(intent); } }); } </code></pre> <p>}</p>
    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.
    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