I am working on quiz app of which user can select 4 types of question difficulties. The questions and answers are stored in string.xml as string arrays.
If all the checkboxes are ticked, the respective string arrays would be stored to ArrayList NUM_ALL_QuestionNames for later quiz retrieval as the questions inside will be further mixed and shuffled.
Full coding as follows:
public class Num_index extends Activity
{
String[] NUM_SIM_QuestionNames;
String[] NUM_MED_QuestionNames;
String[] NUM_DIF_QuestionNames;
String[] NUM_EXP_QuestionNames;
String[] NUM_SIM_AnswerNames;
String[] NUM_MED_AnswerNames;
String[] NUM_DIF_AnswerNames;
String[] NUM_EXP_AnswerNames;
private List<String> NUM_ALL_QuestionNames; // for quiz
private List<String> NUM_ALL_AnswerNames; // for quiz
private int QuestionImport;
private TextView CheckTextView;
private TextView AlertTextView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_num_index);
Button ButtonStart= (Button) findViewById(R.id.buttonStart);
ButtonStart.setOnClickListener(startButtonListener);
CheckTextView = (TextView) findViewById(R.id.checktextView);
AlertTextView = (TextView) findViewById(R.id.alerttextView);
AlertTextView.setText("Start: No alert");
NUM_SIM_QuestionNames = getResources().getStringArray(R.array.Num_Q_Simple_List);
NUM_MED_QuestionNames = getResources().getStringArray(R.array.Num_Q_Medium_List);
NUM_DIF_QuestionNames = getResources().getStringArray(R.array.Num_Q_Diff_List);
NUM_EXP_QuestionNames = getResources().getStringArray(R.array.Num_Q_Expert_List);
NUM_SIM_AnswerNames = getResources().getStringArray(R.array.Num_A_Simple_List);
NUM_MED_AnswerNames = getResources().getStringArray(R.array.Num_A_Medium_List);
NUM_DIF_AnswerNames = getResources().getStringArray(R.array.Num_A_Diff_List);
NUM_EXP_AnswerNames = getResources().getStringArray(R.array.Num_A_Expert_List);
NUM_ALL_QuestionNames = new ArrayList<String>();
NUM_ALL_AnswerNames = new ArrayList<String>();
NUM_ALL_QuestionNames.clear();
NUM_ALL_AnswerNames.clear();
};
private OnClickListener startButtonListener = new OnClickListener()
{
@Override
public void onClick(View v)
{
CheckBox CheckSim = (CheckBox) findViewById(R.id.checkBox2);
CheckBox CheckMed = (CheckBox) findViewById(R.id.checkBox3);
CheckBox CheckDif = (CheckBox) findViewById(R.id.checkBox4);
CheckBox CheckExp = (CheckBox) findViewById(R.id.checkBox5);
if (CheckSim.isChecked())
{
QuestionImport= 0;
QuestionImport = NUM_SIM_QuestionNames.length;
int i =0;
while (i<QuestionImport)
{
String Q_toimport = NUM_SIM_QuestionNames[i];
String A_toimport = NUM_SIM_AnswerNames[i];
NUM_ALL_QuestionNames.add(Q_toimport);
NUM_ALL_AnswerNames.add(A_toimport);
++i;
}
};
// same for other checkbox, not shown here for simplicity //
if ((!CheckSim.isChecked()) && (!CheckMed.isChecked()) && (!CheckDif.isChecked()) && (!CheckExp.isChecked()))
{
int k = 0;
if (NUM_ALL_QuestionNames.size() >0) {k= NUM_ALL_QuestionNames.size();}
CheckTextView.setText(k);
AlertTextView.setText("Please select at least one choice!");
}
if ((CheckSim.isChecked()) || (CheckMed.isChecked()) || (CheckDif.isChecked()) || (CheckExp.isChecked()))
{
int k = 0;
if (NUM_ALL_QuestionNames.size() >0) {k= NUM_ALL_QuestionNames.size();}
CheckTextView.setText(k);
AlertTextView.setText("Have Selection!");
}
}
};
Logcat:
11-17 21:55:41.510: E/AndroidRuntime(12639): FATAL EXCEPTION: main
11-17 21:55:41.510: E/AndroidRuntime(12639): android.content.res.Resources$NotFoundException: String resource ID #0x0
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.content.res.Resources.getText(Resources.java:260)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.widget.TextView.setText(TextView.java:3680)
11-17 21:55:41.510: E/AndroidRuntime(12639): at com.pearappx.iq_3.Num_index$1.onClick(Num_index.java:188)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.view.View.performClick(View.java:3627)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.view.View$PerformClick.run(View.java:14329)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.os.Handler.handleCallback(Handler.java:605)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.os.Handler.dispatchMessage(Handler.java:92)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.os.Looper.loop(Looper.java:137)
11-17 21:55:41.510: E/AndroidRuntime(12639): at android.app.ActivityThread.main(ActivityThread.java:4511)
11-17 21:55:41.510: E/AndroidRuntime(12639): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 21:55:41.510: E/AndroidRuntime(12639): at java.lang.reflect.Method.invoke(Method.java:511)
11-17 21:55:41.510: E/AndroidRuntime(12639): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
11-17 21:55:41.510: E/AndroidRuntime(12639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
11-17 21:55:41.510: E/AndroidRuntime(12639): at dalvik.system.NativeStart.main(Native Method)
Question:
When executing the app, error occurs at line 188, which is the line for
CheckTextView.setText(k);
I would just like to see whether the NUM_ALL_QuestionNames has imported all the strings, i.e. if each of the arrays has 8 values, the CheckTextView will show 32 if all the 4 levels are ticked, and showing 24 if 3 are ticked and so on.
However to solve for the line 188 problem? Many thanks!!