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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:09:58+00:00 2026-05-27T14:09:58+00:00

Here is some of the main code for a little app I have made

  • 0

Here is some of the main code for a little app I have made but there seems to be a runtime problem could someone please have a look and tell me exactly what the problem is:

// there are two button only one for exit and the other to calculate**
public class TimerCodeActivity extends Activity {

    protected Object timebox;    

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

        Button button2 = (Button) findViewById(R.id.button2);
        button2.setOnClickListener(new OnClickListener(){

            @Override    
            public void onClick(View v) {
                finish();
                System.exit(0);}
        });    

        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener(){    

            int digits = Integer.parseInt(((String) timebox).substring(0,2));
            int digits1 = Integer.parseInt(((String) timebox).substring(2,4));
            int digits2 = Integer.parseInt(((String) timebox).substring(4,6));
            int newnumber = ((digits + 777) + (digits1 * 16) + (digits2 * 3)) ;

            @Override
            public void onClick(View v) { 
                Toast.makeText(TimerCodeActivity.this, String.valueOf(newnumber), Toast.LENGTH_LONG).show();
            }
        });
    }
}

the Error Log cat as follows:

D/AndroidRuntime(539): Shutting down VM
W/dalvikvm(539): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
E/AndroidRuntime(539): FATAL EXCEPTION: main
E/AndroidRuntime(539): java.lang.RuntimeException: Unable to start activity        
ComponentInfo{com.Timer.Code/com.Timer.Code.TimerCodeActivity}:   
java.lang.NullPointerException
E/AndroidRuntime(539):  at   
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
E/AndroidRuntime(539):  at   
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime(539):  at   
android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime(539):  at    
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime(539):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(539):  at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(539):  at  
android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(539):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(539):  at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(539):  at   
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(539):  at    
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(539):  at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(539): Caused by: java.lang.NullPointerException
E/AndroidRuntime(539):  at com.Timer.Code.TimerCodeActivity$2.<init>  
(TimerCodeActivity.java:32)
/AndroidRuntime(539):   at     
com.Timer.Code.TimerCodeActivity.onCreate(TimerCodeActivity.java:29)
E/AndroidRuntime(539):  at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(539):  at   
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(539):  at   
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime(539):  ... 11 more

Kindly tell me the problem…Thank you

  • 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-27T14:09:59+00:00Added an answer on May 27, 2026 at 2:09 pm

    I’m guessing it’s a NullPointerException?

    You are initialising the digits with the timebox’s value. But I don’t see the timebox being initialised. I’m also wondering why timebox is an Object, since you are handling it as a String.

    Note: The digits are also being initialised when you call the setOnClickListener, not at the OnClick method.

    EDIT (After comment):

    This should do the trick.

    public class TimerCodeActivity extends Activity {
    
        protected TextView timebox;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.timerlayout);
    
            timebox = (TextView) findViewById(R.id.name_of_textview);
    
            Button button2 = (Button) findViewById(R.id.button2);
            button2.setOnClickListener(new OnClickListener(){
    
                @Override    
                public void onClick(View v) {
                    finish();
                    System.exit(0);}
            });    
    
            Button button1 = (Button) findViewById(R.id.button1);
            button1.setOnClickListener(new OnClickListener(){    
                @Override
                public void onClick(View v) { 
                    String timeboxRepresentation = timebox.getText();
                    int firstDigit = Integer.parseInt(timeboxRepresentation.substring(0,2));
                    int secondDigit = Integer.parseInt(timeboxRepresentation.substring(2,4));
                    int thirdDigit = Integer.parseInt(timeboxRepresentation.substring(4,6));
                    int sum = ((firstDigit + 777) + (secondDigit * 16) + (thirdDigit * 3)) ;
                    Toast.makeText(TimerCodeActivity.this, String.valueOf(sum), Toast.LENGTH_LONG).show();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code here to call minizip(), a boilerplate dirty renamed main() of
I have an app that is a little bit slow. I thoutght it could
This is a bit esoteric, but there have to be a few people here
What am I doing wrong here: class Helo { // main: generate some simple
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's some code (full program follows later in the question): template <typename T> T
Here is some code: class Person def initialize(age) @age = age end def age
Here's some code: DirectorySearcher searcher = new DirectorySearcher(); searcher.Filter = (&(objectClass=user)(sAMAccountName= + lstUsers.SelectedItem.Text +
here is some code I've been working on, basically I need to set up
Here's some example code: class Obj attr :c, true def == that p '=='

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.