Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:48:36+00:00 2026-06-14T20:48:36+00:00

I am making a quiz where the question and answer lists are needed to

  • 0

I am making a quiz where the question and answer lists are needed to pass from activity 1 to activity 2. Relevant Codings extracted as follows:

Activity 1: Num_index.java

   String[] NUM_ALLL_QuestionNames; 
   String[] NUM_ALLL_AnswerNames;   

   @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);

      Button ButtonBackkk= (Button) findViewById(R.id.buttonBackkk);

      CheckTextView = (TextView) findViewById(R.id.checktextView); 

      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>();                              
   };

   private OnClickListener startButtonListener = new OnClickListener() 
   {
      @Override
      public void onClick(View v) 
      {
          CheckBox CheckSim = (CheckBox) findViewById(R.id.checkBox2);
          // other similar checkBox omitted here for simplicity // 

          NUM_ALL_QuestionNames.clear();
          NUM_ALL_AnswerNames.clear();  

          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;                    
              }           
          };    

         // other similar checkBox omitted 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(String.valueOf(k));

                AlertDialog.Builder builder = new AlertDialog.Builder(Num_index.this);
                builder.setTitle("Error");
                builder.setMessage("Please select at least one choice!!");
                builder.setCancelable(false);
                builder.setPositiveButton("OK", null);                 
                AlertDialog ErrorDialog = builder.create();
                ErrorDialog.show();                   
          }

          if ((CheckSim.isChecked()) || (CheckMed.isChecked()) || (CheckDif.isChecked()) || (CheckExp.isChecked()))  
          {
              NUM_ALLL_QuestionNames = new String[NUM_ALL_QuestionNames.size()]; //convert ArrayList<String> to String[]
              NUM_ALLL_AnswerNames = new String[NUM_ALL_AnswerNames.size()]; //convert ArrayList<String> to String[]

              Intent senddata = new Intent (Num_index.this, Num.class); //transmit the list to num.java
              Bundle bundle = new Bundle();
              bundle.putStringArray("dataQ",NUM_ALLL_QuestionNames);
              bundle.putStringArray("dataA",NUM_ALLL_AnswerNames);
              senddata.putExtras(bundle);
              startActivity(senddata);                            

              int k = 0;
              if (NUM_ALLL_QuestionNames.length >0) {k= NUM_ALLL_QuestionNames.length;}
              CheckTextView.setText(String.valueOf(k));                                   
          }           

           Intent intent = new Intent (Num_index.this, Num.class);
           startActivity(intent);
           Num_index.this.finish();               

      } // end method onClick
   }; // end OnClickListener    

Activity 2: Num.java

   private String[] NUM_ALL_QuestionNames;
   private String[] NUM_ALL_AnswerNames;

   @Override
   public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_num); 

      //get bundle from Num_index.java
      Bundle bundle = this.getIntent().getExtras();
      if (bundle!= null)
      {
          NUM_ALL_QuestionNames = bundle.getStringArray("dataQ");
          NUM_ALL_AnswerNames = bundle.getStringArray("dataA");          
      }
      else
      {
          NUM_ALL_QuestionNames = getResources().getStringArray(R.array.Num_Q_Simple_List);
          NUM_ALL_AnswerNames = getResources().getStringArray(R.array.Num_A_Simple_List);             
      }

Logcat:

11-18 20:26:20.905: E/AndroidRuntime(5463): FATAL EXCEPTION: main
11-18 20:26:20.905: E/AndroidRuntime(5463): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pearappx.iq_3/com.pearappx.iq_3.Num}: java.lang.NullPointerException
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.os.Looper.loop(Looper.java:137)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread.main(ActivityThread.java:4511)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at java.lang.reflect.Method.invokeNative(Native Method)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at java.lang.reflect.Method.invoke(Method.java:511)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at dalvik.system.NativeStart.main(Native Method)
11-18 20:26:20.905: E/AndroidRuntime(5463): Caused by: java.lang.NullPointerException
11-18 20:26:20.905: E/AndroidRuntime(5463):     at com.pearappx.iq_3.Num.onCreate(Num.java:73)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.Activity.performCreate(Activity.java:4470)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
11-18 20:26:20.905: E/AndroidRuntime(5463):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)

Line 73 is

NUM_ALL_QuestionNames = bundle.getStringArray("dataQ"); 

which means the StringArray is not properly stored in Activity1 or cannot properly fetched in Activity2. It shows NullPointerException.

Question:

I have searched through this website like String back from Bundle , and How to pass the selectedListItem's object to another activity? and follow the method described but still fails. But why it is NullPointerException? How can this be tackled?

Many thanks!!

PS: In Activity 1 I have

              if (NUM_ALLL_QuestionNames.length >0) {k= NUM_ALLL_QuestionNames.length;}
              CheckTextView.setText(String.valueOf(k)); 

and k gives out a correct number of items. This means NUM_ALLL_QuestionNames is not blank.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:48:37+00:00Added an answer on June 14, 2026 at 8:48 pm

    As in your Current Code You are starting Num.class Activity two Times first using startActivity(senddata); and second time startActivity(intent); which contains no bundle object that’s why you are getting NullPointerException

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a quiz application with question and answer. I want to make
I'm making a simple quiz database, where a question has an answer and one
I am making a quiz application in J2ME. Questions and answers will come from
I'm making a quiz in Actionscript 2.0. The quiz has 8 questions. Each question
Making a simple three question PHP quiz. Each question is displayed on a page
Here's the quiz question: Adding two strings or making multiple copies of the same
I'm making a flash quiz which will have a series of questions. Each question
I am making a Quiz program. So what I want is whenever any question
i'm making an android quiz app. there are have one question an four answers,
Hey I'm making a quiz application and I need to pass an ArrayList of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.