2014-01-19 2 views
0

하나의 활동 데이터를 다른 활동으로 전달하려고했습니다. 해당 데이터는 Spinners에서 가져옵니다. 응용 프로그램을 실행하려고하면 오류가 표시됩니다. 누구든지 나를 도울 수 있습니까? Spinner에서 전달한 여분의 데이터를로드 할 수 없습니다.

이이 제 2 회 활동 1 활동

Spinner dress,food,price,time; 
    String txt_dress,txt_price,txt_food,txt_time,restName; 
    Button btnSearch; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.advance_searech); 

     dress = (Spinner) findViewById(R.id.spinner1); 
     price= (Spinner) findViewById(R.id.planets_spinner); 
     food= (Spinner) findViewById(R.id.spinner2); 
     time= (Spinner) findViewById(R.id.spinner3); 

     btnSearch = (Button) findViewById(R.id.button1); 

     btnSearch.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 


       txt_dress = dress.getSelectedItem().toString(); 
       txt_food = food.getSelectedItem().toString(); 
       txt_price = price.getSelectedItem().toString(); 
       txt_time = time.getSelectedItem().toString(); 
       Log.d("Dress", txt_dress); 

       Intent intent = new Intent(AdvanceSearch.this,AdvanceSearchResult.class); 
       intent.putExtra("txt_price", txt_price); 
       intent.putExtra("txt_dress", txt_dress); 
       intent.putExtra("txt_time", txt_time); 
       intent.putExtra("txt_food", txt_food); 
       startActivity(intent); 
      } 
     }); 
    } 

되는 XML

<Spinner 
     android:id="@+id/spinner1" 
     android:layout_width="200dp" 
     android:layout_height="40dp" 
     android:layout_alignLeft="@+id/planets_spinner" 
     android:layout_below="@+id/textView1" 
     android:entries="@array/price_list" /> 



    <Spinner 
     android:id="@+id/planets_spinner" 
     android:layout_width="200dp" 
     android:layout_height="40dp" 
     android:layout_alignLeft="@+id/textView4" 
     android:layout_below="@+id/textView2" 
     android:layout_marginTop="19dp" 
     android:entries="@array/Food" /> 

    <Spinner 
     android:id="@+id/spinner2" 
     android:layout_width="200dp" 
     android:layout_height="40dp" 
     android:layout_alignLeft="@+id/planets_spinner" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="16dp" 
     android:entries="@array/dress" /> 
<Spinner 
     android:id="@+id/spinner3" 
     android:layout_width="200dp" 
     android:layout_height="40dp" 
     android:layout_alignLeft="@+id/textView4" 
     android:layout_below="@+id/textView4" 
     android:layout_marginTop="30dp" 
     android:entries="@array/time" /> 

입니다

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.advance_result); 

    Intent i = getIntent(); 
    String price = i.getStringExtra("txt_price"); 

    Toast.makeText(getApplicationContext(), price, Toast.LENGTH_LONG).show(); 

} 

이 오류

01-19 12:07:02.571: E/AndroidRuntime(10020): FATAL EXCEPTION: main 
01-19 12:07:02.571: E/AndroidRuntime(10020): java.lang.NullPointerException 
01-19 12:07:02.571: E/AndroidRuntime(10020): at com.example.rp.AdvanceSearch$1.onClick(AdvanceSearch.java:46) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.view.View.performClick(View.java:4191) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.view.View$PerformClick.run(View.java:17229) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.os.Handler.handleCallback(Handler.java:615) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.os.Handler.dispatchMessage(Handler.java:92) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.os.Looper.loop(Looper.java:137) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at android.app.ActivityThread.main(ActivityThread.java:4960) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at java.lang.reflect.Method.invokeNative(Native Method) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at java.lang.reflect.Method.invoke(Method.java:511) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
01-19 12:07:02.571: E/AndroidRuntime(10020): at dalvik.system.NativeStart.main(Native Method) 
입니다3210
+0

dress = (Spinner) findViewById(R.id.spinner1); food = (Spinner) findViewById(R.id.planets_spinner); dress = (Spinner) findViewById(R.id.spinner2); food = (Spinner) findViewById(R.id.spinner3); 

변경입니까? – Raghunandan

+0

'Spinner.getSelectedItem()'이 'null'을 반환하고 있다고 생각합니다. –

+0

@GopalRao 예. 왜 그런가요? 어떤 생각있어? – anuruddhika

답변

2
다음

pricetime는 초기화되지 않으며, 당신이 onCLick

price.getSelectedItem().toString(); 
time.getSelectedItem().toString(); 

에서하고 있기 때문에 그래서 라인 (46) 무엇

dress = (Spinner) findViewById(R.id.spinner1); 
food = (Spinner) findViewById(R.id.planets_spinner); 
price = (Spinner) findViewById(R.id.spinner2); 
time = (Spinner) findViewById(R.id.spinner3); 
+0

Thanks @Name은 표시 할 수 없습니다. 나는 그것을 보지 못했다. 이제는 작품입니다. – anuruddhika

+0

환영합니다 :) ** 복사 컷 ** 문제 : P –

+0

@anuruddhika 문제가 해결 된 것 같습니다. 도움이된다면이 대답을 수락 할 수 있습니다 ... –

관련 문제