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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:37:31+00:00 2026-05-27T00:37:31+00:00

I’m doing a test to get Android development up in Eclipse. My application crashes

  • 0

I’m doing a test to get Android development up in Eclipse. My application crashes when the calculate button is pressed. It would appear that the problem is with the AlertDialog, but all of the examples that I’ve found have it the same way.

package mobile.ildu.AndroidTest;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class AndroidTestActivity extends Activity {
    private EditText text1;
    private EditText text2;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void myClickHandler(View view)
    {
        switch(view.getId())
        {
            case R.id.calculate:
                if(text1.getText().length()==0)
                {
                    callDialog("Error","You must enter a number in the first box");
                    return;
                }
                if(text2.getText().length()==0)
                {
                    callDialog("Error","You must enter a number in the second box");
                    return;
                }
                float number1 = Float.parseFloat(text1.getText().toString());
                float number2 = Float.parseFloat(text2.getText().toString());
                float answer = number1*number2;
                callDialog("Answer",number1+"*"+number2+" = "+answer);
                break;
        }
    }

    private void callDialog(String title, String message)
    {
        AlertDialog alertDialog= new AlertDialog.Builder(AndroidTestActivity.this).create();
        alertDialog.setTitle(title);   
        alertDialog.setMessage(message);
        alertDialog.setButton("Close", new DialogInterface.OnClickListener() 
        {         
            public void onClick(DialogInterface dialog, int which) 
            {
                dialog.dismiss();
            }
        });
        alertDialog.show();
    }
}

error log:

11-22 10:41:45.092: E/AndroidRuntime(675): FATAL EXCEPTION: main
11-22 10:41:45.092: E/AndroidRuntime(675): java.lang.IllegalStateException: Could not execute method of the activity
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.view.View$1.onClick(View.java:3019)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.view.View.performClick(View.java:3460)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.view.View$PerformClick.run(View.java:13955)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.os.Handler.handleCallback(Handler.java:605)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.os.Looper.loop(Looper.java:137)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.app.ActivityThread.main(ActivityThread.java:4340)
11-22 10:41:45.092: E/AndroidRuntime(675):  at java.lang.reflect.Method.invokeNative(Native Method)
11-22 10:41:45.092: E/AndroidRuntime(675):  at java.lang.reflect.Method.invoke(Method.java:511)
11-22 10:41:45.092: E/AndroidRuntime(675):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-22 10:41:45.092: E/AndroidRuntime(675):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-22 10:41:45.092: E/AndroidRuntime(675):  at dalvik.system.NativeStart.main(Native Method)
11-22 10:41:45.092: E/AndroidRuntime(675): Caused by: java.lang.reflect.InvocationTargetException
11-22 10:41:45.092: E/AndroidRuntime(675):  at java.lang.reflect.Method.invokeNative(Native Method)
11-22 10:41:45.092: E/AndroidRuntime(675):  at java.lang.reflect.Method.invoke(Method.java:511)
11-22 10:41:45.092: E/AndroidRuntime(675):  at android.view.View$1.onClick(View.java:3014)
11-22 10:41:45.092: E/AndroidRuntime(675):  ... 11 more
11-22 10:41:45.092: E/AndroidRuntime(675): Caused by: java.lang.NullPointerException
11-22 10:41:45.092: E/AndroidRuntime(675):  at mobile.ildu.AndroidTest.AndroidTestActivity.myClickHandler(AndroidTestActivity.java:27)
11-22 10:41:45.092: E/AndroidRuntime(675):  ... 14 more

Thanks for any help!

  • 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-27T00:37:31+00:00Added an answer on May 27, 2026 at 12:37 am

    Try this:

    package mobile.ildu.AndroidTest;
    
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class AndroidTestActivity extends Activity {
        private EditText text1;
        private EditText text2;
        private Button button;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            text1 = (EditText)findViewById(R.id.text1);
            text2 = (EditText)findViewById(R.id.text2);
            button = (Button) findViewById(R.id.calculate);
    
            button.setOnClickListener(new  OnClickListener() {
    
                public void onClick(View arg0) {
    
                    if(text1.getText().length()==0)
                    {
                        callDialog("Error","You must enter a number in the first box");
                        return;
                    }
                    if(text2.getText().length()==0)
                    {
                        callDialog("Error","You must enter a number in the second box");
                        return;
                    }
                    float number1 = Float.parseFloat(text1.getText().toString());
                    float number2 = Float.parseFloat(text2.getText().toString());
                    float answer = number1*number2;
                    callDialog("Answer",number1+"*"+number2+" = "+answer);
                }
            });
        }
    
        private void callDialog(String title, String message)
        {
            AlertDialog alertDialog= new AlertDialog.Builder(AndroidTestActivity.this).create();
            alertDialog.setTitle(title);   
            alertDialog.setMessage(message);
            alertDialog.setButton("Close", new DialogInterface.OnClickListener() 
            {         
                public void onClick(DialogInterface dialog, int which) 
                {
                    dialog.dismiss();
                }
            });
            alertDialog.show();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I need a function that will clean a strings' special characters. I do NOT

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.