2013-05-06 1 views
0

Im new to android.키 문자열 배열 예상 문자열 [], 값은 java.util.ArrayList

의도를 사용하여 한 클래스에서 다른 클래스로 배열 값을 가져 오는 방법 ?? 나는이 같은 노력

... 1 활동 ...

Intent videointent = new Intent(Focusarea.this,Videoplayer.class); 
videointent.putExtra("string-array", resim_list); 
startActivity(videointent); 

2 활동

 Intent intent=getIntent(); 
    String [] Array = intent.getStringArrayExtra("string-array"); 

임이 경고 및 메신저 점점로 널 (null)을 받고 2 초 활동의 값으로 ..

 W/Bundle(521): Key string-array expected String[] but value was a 
    java.util.ArrayList. The default value <null> was returned. 
    W/Bundle(521): Attempt to cast generated internal exception: 
    W/Bundle(521): java.lang.ClassCastException: java.util.ArrayList 
    W/Bundle(521):  at android.os.Bundle.getStringArray(Bundle.java:1459) 
    W/Bundle(521):  at 
    android.content.Intent.getStringArrayExtra(Intent.java:3630) 
     W/Bundle(521): at 
    com.example.TEENEINSTIEN.Videoplayer.onCreate(Videoplayer.java:20) 
     W/Bundle(521): at 
     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 

답변

1

는 사용하십시오 Bundle :

Videoplayer 활동보다
Bundle bundle = new Bundle(); 
bundle.putStringArray("string-array", resim_list); 
videointent.putExtras(bundle); 

:

Bundle bundle = getIntent().getExtras(); 
String [] myStringArray = bundle.getStringArray("string-array"); 

편집 : 문제는 String[] 또는 ArrayList의 경우 resim_list 조금 unclair입니다에 . resim_list 만약 는 ArrayList

bundle.putStringArrayList("string-array", resim_list); 

를 저장하고

bundle.getStringArrayList("string-array") 

그것이

+0

startActivity. 평소처럼. – Blackbelt

+0

은 resim_list 문자열 배열입니까? – Blackbelt

+0

ArrayList

0

어쩌면 당신의 resim_list 인스턴스 당신은 문자열을 저장해야합니다 ArrayList에

입니다 검색하는 것입니다 []와 :

videointent.putExtra("string-array", resim_list.toArray(new String[resim_list.size()])); 
+0

예 ArrayList

+0

두 번째 활동에서 어떻게 얻습니까? –

+0

이미했던 것과 같은 방식입니다. –