0

あるアクティビティ (Second.class) からテキストを取得し、それを別のアクティビティ (Third.class) に渡そうとしています。取得しようとしている文字列は、空港コードの TextView です。

これは、問題を引き起こしていると思われるコードです

    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);
        }

    }); 

そして私の3番目のクラス

    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);
    }

これは、アプリを実行したときの Log Cat です

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)

Eclipse はエラーを表示しません (logCat 以外)。前もって感謝します

私の完全なセカンドクラス

      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);
        }

    }); 


}

}

4

4 に答える 4