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 8600387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:36:21+00:00 2026-06-12T01:36:21+00:00

Why is this one line crashing my app? It even happens with set clickable.

  • 0

Why is this one line crashing my app? It even happens with set clickable. Without the line, it’s fine, but with it – it won’t even go into the activity.

continueButton.setEnabled(false);

here is the logcat.

09-30 16:05:09.352: E/AndroidRuntime(755): FATAL EXCEPTION: main
09-30 16:05:09.352: E/AndroidRuntime(755): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mangodeveloper.mcathomie/com.mangodeveloper.mcathomie.McatActivityGame}: java.lang.NullPointerException
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.os.Looper.loop(Looper.java:123)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-30 16:05:09.352: E/AndroidRuntime(755):  at java.lang.reflect.Method.invokeNative(Native Method)
09-30 16:05:09.352: E/AndroidRuntime(755):  at java.lang.reflect.Method.invoke(Method.java:507)
09-30 16:05:09.352: E/AndroidRuntime(755):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-30 16:05:09.352: E/AndroidRuntime(755):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-30 16:05:09.352: E/AndroidRuntime(755):  at dalvik.system.NativeStart.main(Native Method)
09-30 16:05:09.352: E/AndroidRuntime(755): Caused by: java.lang.NullPointerException
09-30 16:05:09.352: E/AndroidRuntime(755):  at com.mangodeveloper.mcathomie.McatActivityGame.onCreate(McatActivityGame.java:40)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-30 16:05:09.352: E/AndroidRuntime(755):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-30 16:05:09.352: E/AndroidRuntime(755):  ... 11 more

here is the entire activity as of now:

package com.mangodeveloper.mcathomie;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class McatActivityGame extends Activity {

    private static int GAME_PREFERENCES_MAXROUNDS = 1, GAME_PREFERENCES_CURRENTROUND;
    private Cursor c;
    private RadioGroup radioGrp;
    private Button continueButton, pauseButton, explainButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        radioGrp = (RadioGroup) findViewById(R.id.radioGroup1);
        continueButton = (Button) findViewById(R.id.button_continue); 
        pauseButton = (Button) findViewById(R.id.button_pause); 
        explainButton = (Button)findViewById(R.id.button_explanation);  

        setContentView(R.layout.activity_game);
        McatDatabase dbHelper = new McatDatabase(this);
        c = dbHelper.getQuestions();

        c.moveToFirst();
        fillQuestions();
        continueButton.setEnabled(false);

//      radioGrp.setOnClickListener(new OnClickListener() {
//          
//          public void onClick(View v) {
//              continueButton.setEnabled(true);
//          }
//      });

//      continueButton.setOnClickListener(new OnClickListener() {
//          public void onClick(View v) {
//              int selectedId = radioGrp.getCheckedRadioButtonId();
//              RadioButton radioBttnSelected = (RadioButton) findViewById(selectedId);
//              if (radioBttnSelected.getText() == answer1) {
//                  Toast.makeText(McatActivityGame.this, "Correct Answer!", Toast.LENGTH_SHORT).show();
//              }else{Toast.makeText(McatActivityGame.this, "Not correct, please try again", Toast.LENGTH_SHORT).show();
//              }
//          }
//      });



//      nextquestionButton.setOnClickListener(new OnClickListener() {
//
//          public void onClick(View v) {
//              GAME_PREFERENCES_CURRENTROUND++;
//              GAME_PREFERENCES_MAXROUNDS = getIntent().getExtras().getInt("MAXROUNDS");
//
//              if (GAME_PREFERENCES_CURRENTROUND > GAME_PREFERENCES_MAXROUNDS) {
//                  Toast.makeText(McatActivityGame.this, "Alert Dialog stuff", Toast.LENGTH_SHORT).show();
//              }else{
//                  c.moveToNext(); 
//                  fillQuestions();
//              }
//          }
//      });     
//      

    }

    private void fillQuestions() {  
//      shuffle questions
        List<String> shuffAnswr = new ArrayList<String>(4);
        shuffAnswr.add(c.getString(3));
        shuffAnswr.add(c.getString(4));
        shuffAnswr.add(c.getString(5));
        shuffAnswr.add(c.getString(6));
        Collections.shuffle(shuffAnswr);        

//      instantiate 
        TextView questionTv = (TextView) findViewById(R.id.textView0);  
        RadioButton rd0 = (RadioButton)findViewById(R.id.radio0),
                rd1 = (RadioButton)findViewById(R.id.radio1),
                rd2 = (RadioButton)findViewById(R.id.radio2),
                rd3 = (RadioButton)findViewById(R.id.radio3);

//      set questions
        questionTv.setText(c.getString(2));
        rd0.setText(shuffAnswr.get(0));
        rd1.setText(shuffAnswr.get(1));
        rd2.setText(shuffAnswr.get(2));
        rd3.setText(shuffAnswr.get(3));
    }

}
  • 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-12T01:36:22+00:00Added an answer on June 12, 2026 at 1:36 am

    Change your onCreate to the following:

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_game);//This got moved up
    
            radioGrp = (RadioGroup) findViewById(R.id.radioGroup1);
            continueButton = (Button) findViewById(R.id.button_continue); 
            pauseButton = (Button) findViewById(R.id.button_pause); 
            explainButton = (Button)findViewById(R.id.button_explanation);  
    
            McatDatabase dbHelper = new McatDatabase(this);
            c = dbHelper.getQuestions();
    
            c.moveToFirst();
            fillQuestions();
            continueButton.setEnabled(false);
            ....... //Rest of your code
    

    You were getting an error because you were trying to get a reference to the Views in the layout before the layout had been inflated. You must always call setContentView() before using findViewById().

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

Sidebar

Related Questions

Is it possible to convert this if statement into a one line statement ?
I know there is a lot of documentation around this but this one line
This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50
What is a good way of writing something like this in one line. The
ok I give up, how do you do this in one line? public object
if I have a text file like this : this is line one This
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
This code on an html page comes in as one line. Why isn't backslash
I want this text all on one line, not spaced on two sepearate lines.
I have this code that where I would normally use one line: if (tableView

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.