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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:28:09+00:00 2026-06-11T06:28:09+00:00

I am creating sort of an app where there are many buttons with different

  • 0

I am creating sort of an app where there are many buttons with different digits each (0-9). When I click on a button I want to display its number to the edittext field. Sort of lie a calculator. Here is my code below:

public class GameActivity extends Activity {

TextView timer;
Button button1;
EditText et;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameactivity);
    Intent mIntent = getIntent();
    int seconds = getIntent().getIntExtra("seconds", 0);

    EditText et = (EditText) findViewById(R.id.editText1);
    final TextView timer = (TextView) findViewById(R.id.textViewtimer);
    new CountDownTimer(seconds, 1000) {

         public void onTick(long millisUntilFinished) {
             timer.setText("Seconds remaining: " + millisUntilFinished / 1000);
         }

         public void onFinish() {
             Intent intent = new Intent(GameActivity.this, Main.class);
             startActivity(intent);
         }
      }.start();
}

public void one (View v){
int n = 1;
et.setText(n);
}

Here is the error i am getting:

09-12 12:21:25.778: E/AndroidRuntime(3658): FATAL EXCEPTION: main
09-12 12:21:25.778: E/AndroidRuntime(3658): java.lang.IllegalStateException: Could not execute method of the activity
09-12 12:21:25.778: E/AndroidRuntime(3658):     at  android.view.View$1.onClick(View.java:2144)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.view.View.performClick(View.java:2485)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.view.View$PerformClick.run(View.java:9080)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.os.Handler.handleCallback(Handler.java:587)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.os.Looper.loop(Looper.java:123)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at   java.lang.reflect.Method.invoke(Method.java:507)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at dalvik.system.NativeStart.main(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658): Caused by: java.lang.reflect.InvocationTargetException
09-12 12:21:25.778: E/AndroidRuntime(3658):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at  java.lang.reflect.Method.invoke(Method.java:507)
09-12 12:21:25.778: E/AndroidRuntime(3658):     at  android.view.View$1.onClick(View.java:2139)
09-12 12:21:25.778: E/AndroidRuntime(3658):     ... 11 more
09-12 12:21:25.778: E/AndroidRuntime(3658): Caused by: java.lang.NullPointerException
09-12 12:21:25.778: E/AndroidRuntime(3658):     at com.dtan.mathwiz.GameActivity.one(GameActivity.java:42)
09-12 12:21:25.778: E/AndroidRuntime(3658):     ... 14 more
  • 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-11T06:28:10+00:00Added an answer on June 11, 2026 at 6:28 am

    Because of this –

    ....
    int seconds = getIntent().getIntExtra("seconds", 0);
    
    EditText et = (EditText) findViewById(R.id.editText1);           // Already declared in global
    final TextView timer = (TextView) findViewById(R.id.textViewtimer);
    ....
    

    You declared your EditText globaly and initialized in onCreate with new Declaration. The method one method consider the EditText‘s object from global one only. So, it(et) is being as null. So, better remove the declaration inside of onCreate and do the code like below –

    ....
    int seconds = getIntent().getIntExtra("seconds", 0);
    
    et = (EditText) findViewById(R.id.editText1);
    final TextView timer = (TextView) findViewById(R.id.textViewtimer);
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in creating a sort of hand-off authentication method, where there's a client
I'm developping a sort of camera app, and I need it to save each
I am creating buttons dynamically for a user-based app. Now I have to tell
I'm creating a C# WPF app with SQLCE. Each time before I debug, I
I am creating an image (some sort of copy of another gallery image) using
Is it possible to define some sort of capitalize() or toLowerCase() function when creating
I am in the process of creating an outlook addin. The addin works sort
Using Jquery TableSorter, I am creating a custom parser to sort elapsed time <td>
Creating an a app, where I store bunch of photos in the drawable folder,
I need to create a simple app which can display geometries from Oracle Spatial

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.