オブジェクトのArrayListをインテントで渡そうとしていますが、動作させることができません。ここで私が持っているものです。インテントによるオブジェクトのArrayListの受け渡し - Java(Android)
public class QuestionView extends Activity {
//variables and other methods...
public void endQuiz() {
Intent intent = new Intent(QuestionView.this, Results.class);
intent.putExtra("correctAnswers", correctAnswers);
intent.putExtra("wrongAnswers", wrongAnswers);
intent.putParcelableArrayListExtra("queries", queries);
startActivity(intent);
}
}
インテントは、ここに受信されている:
public class Results extends Activity {
int cAnswers;
int wAnswers;
ArrayList<Question> qs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultsmain);
cAnswers = getIntent().getIntExtra("correctAnswers", -1);
wAnswers = getIntent().getIntExtra("wrongAnswers", -1);
qs = getIntent().getParcelableArrayListExtra("queries");
//more code...
}
}
2つのint、correctAnswerとwrongAnswersは、受信されていると私はそれらを使用することができます。 ArrrayListは通っていません。 endQuiz()メソッドではエラーは発生しませんが、 'qs = getIntent()。getParcelableArrayListExtra( "queries");'エラーを投げて「Bound Mismatch」と言っています。
これに関するお手伝いがあります。
質問クラス:
public class Question {
String a1;
String a2;
String a3;
String a4;
int correctAnswer;
String query;
int selectedAnswer;
boolean correctness;
public Question() {
}
public Question(String a1, String a2, String a3, String a4, int correctAnswer, String query, int selectedAnswer, boolean correctness) {
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
this.a4 = a4;
this.correctAnswer = correctAnswer;
this.query = query;
this.selectedAnswer = selectedAnswer;
this.correctness = correctness;
}
}
あなたの 'Question'クラスは[Parcelable](http://developer.android.com/reference/android/os/Parcelable.html)を実装していますか? – wsanville
いいえ...彼がなぜそれをキャストしているのか...(ArrayList <?extends Parcelable>); ':)確かに助けにならないでしょう – Selvin
ArrayListの実際の型はどういうものが見えますか?私はクラスを意味します... – LuxuryMode