मैं इरादे के माध्यम से ऑब्जेक्ट्स के ऐरेलिस्ट को पास करने की कोशिश कर रहा हूं लेकिन इसे काम नहीं कर सकता। यहाँ मैं क्या है:इरादे के माध्यम से ऑब्जेक्ट्स के ऑरेलिस्ट को पास करना - जावा (एंड्रॉइड)
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...
}
}
दो ints, correctAnswer और wrongAnswers, प्राप्त किया जा रहा है और मैं उन्हें इस्तेमाल कर सकते हैं। ArrrayList के माध्यम से नहीं आ रहा है। EndQuiz() विधि में कोई त्रुटि नहीं है लेकिन 'qs = getIntent()। GetParcelableArrayListExtra ("query");' एक त्रुटि फेंक रहा है और कह रहा है "बाउंड मिस्चैच।"
इस पर कोई मदद की सराहना की जाती है!
प्रश्न वर्ग:
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;
}
}
क्या आपका 'प्रश्न' वर्ग लागू [पार्ससेलबल] (http://developer.android.com/reference/android/os/Parcelable.html) है? – wsanville
नहीं ... यही कारण है कि वह इसे कास्टिंग कर रहा है ... '(ArrayList पार्ससेल योग्य>> प्रश्नों को बढ़ाता है);' :) जो निश्चित रूप से – Selvin
की सहायता नहीं करेगा क्या हम देख सकते हैं कि आपके प्रश्नों का प्रकार वास्तव में कैरे जैसा दिखता है? मेरा मतलब वर्ग है ... – LuxuryMode