にデータを入力ArrayList<Long>
していQuestionView.java
ます。私はそれをクラスに渡し、それをクラスのaでResults.java
呼び出しています。 ArrayList<Long>
dialog
Results.java
それが意味をなさなかった場合はお知らせください。さらに明確にしようと思います。すべてのコードとLogCatの出力は以下のとおりです。前もって感謝します!
QuestionView.java
public class QuestionView extends Activity {
ArrayList<Long> pointsPerQuestion = new ArrayList<Long>(10);
public void onCreate(Bundle savedInstanceState) {
....
}
public ArrayList<Long> getPointsPerQuestion() {
return pointsPerQuestion;
}
public void nextQuestion() {
pointsPerQuestion.add(points);
score = score + points;
i++;
loadQuestion();
}
public class Timer extends CountDownTimer {
@Override
public void onFinish() {
...
}
@Override
public void onTick(long millisUntilFinished) {
bar.setProgress((int) millisUntilFinished);
points = (millisUntilFinished / 100) / 2;
timeremaining.setText("Points remaining: " + points);
if(i < 10) {
questionNumber.setText("Question " + (i + 1) + " of 10");
}
}
Results.java
public class Results extends Activity {
QuestionView qv = new QuestionView();
ArrayList<Question> queryList = qv.getQueries();
ArrayList<Question> qs;
ArrayList<Long> pointsPerQuestion;
ArrayList<Button> buttonList = new ArrayList<Button>(10);
final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultsmain);
qs = getIntent().getParcelableArrayListExtra("queries");
pointsPerQuestion = qv.getPointsPerQuestion();
q1details.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.q1details);
dialog.setTitle("Question 1 Details");
ImageView image = (ImageView)dialog.findViewById(R.id.image);
TextView question = (TextView)dialog.findViewById(R.id.question);
TextView selectedAnswer = (TextView)dialog.findViewById(R.id.selectedAnswer);
TextView correctAnswer = (TextView)dialog.findViewById(R.id.correctAnswer);
TextView points = (TextView)dialog.findViewById(R.id.points);
TextView verse = (TextView)dialog.findViewById(R.id.verse);
Button close = (Button)dialog.findViewById(R.id.close);
if(qs.get(0).getSelectedAnswer() == qs.get(1).getCorrectAnswer()) {
image.setBackgroundResource(R.drawable.green_check_mark);
} else {
image.setBackgroundResource(R.drawable.red_x);
}
question.setText(qs.get(0).getQuery());
selectedAnswer.setText("" + qs.get(0).getSelectedAnswer());
correctAnswer.setText("" + qs.get(0).getCorrectAnswer());
points.setText("" + pointsPerQuestion.get(0)); //Line 120
verse.setText(qs.get(0).getVerse());
close.setText("Close");
close.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
LogCat出力
02-14 15:21:13.281: E/AndroidRuntime(1519): FATAL EXCEPTION: main
02-14 15:21:13.281: E/AndroidRuntime(1519): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
02-14 15:21:13.281: E/AndroidRuntime(1519): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
02-14 15:21:13.281: E/AndroidRuntime(1519): at java.util.ArrayList.get(ArrayList.java:304)
02-14 15:21:13.281: E/AndroidRuntime(1519): at matt.lyons.bibletrivia.Results$4.onClick(Results.java:120)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.view.View.performClick(View.java:4202)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.view.View$PerformClick.run(View.java:17340)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.os.Handler.handleCallback(Handler.java:725)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.os.Handler.dispatchMessage(Handler.java:92)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.os.Looper.loop(Looper.java:137)
02-14 15:21:13.281: E/AndroidRuntime(1519): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-14 15:21:13.281: E/AndroidRuntime(1519): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 15:21:13.281: E/AndroidRuntime(1519): at java.lang.reflect.Method.invoke(Method.java:511)
02-14 15:21:13.281: E/AndroidRuntime(1519): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-14 15:21:13.281: E/AndroidRuntime(1519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-14 15:21:13.281: E/AndroidRuntime(1519): at dalvik.system.NativeStart.main(Native Method)
編集
このコード行を入れても:
long x = 666;
pointsPerQuestion.add(x);
私のonCreate()
メソッドでは、同じエラーが発生します。クラスのgetPointsPerQuestion()
メソッドが機能していない可能性がありますか?QuestionView