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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:26:44+00:00 2026-05-20T18:26:44+00:00

Well, my program keeps giveing me a null point exception and I don’t know

  • 0

Well, my program keeps giveing me a null point exception and I don’t know why? I know it has something to do with the lvl variable, but I don’t know what? What can I do to fix this problem?

Logcat:

03-18 16:14:55.852: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
03-18 16:14:55.852: ERROR/AndroidRuntime(277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.games.think/com.games.think.Think}: java.lang.NullPointerException
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.os.Looper.loop(Looper.java:123)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invokeNative(Native Method)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invoke(Method.java:521)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at dalvik.system.NativeStart.main(Native Method)
03-18 16:14:55.852: ERROR/AndroidRuntime(277): Caused by: java.lang.NullPointerException
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at com.games.think.Think.onCreate(Think.java:38)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-18 16:14:55.852: ERROR/AndroidRuntime(277):     ... 11 more

Here is some of my code:

     package com.games.think;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class Think extends Activity implements OnClickListener{

    int question = 1, lvl;

    /** Called when the activity is first created. */
    RadioButton lvl1;
    RadioButton lvl2;
    RadioButton lvl3;
    RadioButton lvl4;
    RadioButton lvl5;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button play = (Button)findViewById(R.id.play);
        play.setOnClickListener(this);
        Button level = (Button)findViewById(R.id.level);
        level.setOnClickListener(this);
        Button exit = (Button)findViewById(R.id.exit);
        exit.setOnClickListener(this);
        Button setLevel = (Button)findViewById(R.id.setLevel);
        setLevel.setOnClickListener(this);
        lvl1 = (RadioButton)findViewById(R.id.lvl1);
        lvl2 = (RadioButton)findViewById(R.id.lvl2);
        lvl3 = (RadioButton)findViewById(R.id.lvl3);
        lvl4 = (RadioButton)findViewById(R.id.lvl4);
        lvl5 = (RadioButton)findViewById(R.id.lvl5);

        lvl = getLevel();
        if(lvl == -1) {
            lvl=getLevel();
        }


    }

    @SuppressWarnings("null")
    private int getLevel() {

        String FILENAME = "think_level";
        FileInputStream fis;
        byte[] buffer = new byte[1000];



        try {
            fis = openFileInput(FILENAME);
        } catch (FileNotFoundException e) {
            setLevel("1");
            return -1;
        }

        try {
            fis.read(buffer,0,1000);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            fis.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String level = buffer.toString();
        int iLevel = Integer.valueOf(level);
        return iLevel;
    }

    private void setLevel(String level) {
        String FILENAME = "think_level";
        String string = level;

        FileOutputStream fos;
        try {
            fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
            fos.write(string.getBytes());
            fos.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }

    }

    @Override
    public void onClick(View v) {
        switch( v.getId()){
        case R.id.play:
            setContentView(R.layout.play);
            setQuestion();
        case R.id.level:
            setContentView(R.layout.level);
            switch(getLevel()) {
            case 1:
                lvl1.setChecked(true);
            case 2:
                lvl2.setChecked(true);
            case 3:
                lvl3.setChecked(true);
            case 4:
                lvl4.setChecked(true);
            case 5:
                lvl5.setChecked(true);

            }

        case R.id.setLevel:
            if(lvl1.isChecked()) {
                setLevel("1");
            }
            if(lvl2.isChecked()) {
                setLevel("2");
            }
            if(lvl3.isChecked()) {
                setLevel("3");
            }
            if(lvl4.isChecked()) {
                setLevel("4");
            }
            if(lvl5.isChecked()) {
                setLevel("5");
            }







        }
    }

    private void setQuestion() {




    }



    }
  • 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-05-20T18:26:44+00:00Added an answer on May 20, 2026 at 6:26 pm

    Check if the button with id “setLevel” is in your main.xml. If it is somewhere else, you can not find it like this:

     Button setLevel = (Button)findViewById(R.id.setLevel);
    

    But you need an inflater.

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

Sidebar

Related Questions

I setup a FSEvent that runs well but it keeps reporting the same event
In a pylab program (which could probably be a matlab program as well) I
Well I testing my jython program, that does some neat [.xls, .doc, .rtf, .tif,
Well I found a nice tutorial about how to program applications using Bonjour. It's
We have a Perl program that ran well on all Windows platforms so far.
Well, I have this bit of code that is slowing down the program hugely
I've debugged my program and the arrays seem to be allocated well. However for
I have a popup function in a program that works well, be re-loads the
I have a client program that consumes a web service. It works quite well
Hi im learning LISP and well, all day i program php for a living,

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.