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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:13:38+00:00 2026-06-09T01:13:38+00:00

here is the java… can someone tell me whats wrong here? The error may

  • 0

here is the java… can someone tell me whats wrong here? The error may be in here i figure the main error in the logcat(Below) is a Null Pointer… I may be wrong though… Thank you all in advance!!!

package tip.calculator;


import android.os.Bundle;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import android.widget.Button;




public class TipCalculator extends Activity 
{

private Button enter;
EditText myEditField ;
EditText myEditField2;
float percentage = 0;
float percentageInp = 0;
float billAmount = 0;
double output = 0; 
String output1 = "";
Button clearButton ;
TextView textView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myEditField = (EditText) findViewById(R.id.percentText);
    enter = (Button)findViewById(R.id.button1);
    myEditField2 = (EditText) findViewById(R.id.billText);



    enter.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {

             TextView errors;
             textView = (TextView) findViewById(R.id.textView1);
             errors = (TextView) findViewById(R.id.errorText);    
             clearButton = (Button) findViewById(R.id.clearButton);

             for(;;){

             if(myEditField == null){
                 errors.setText("Percent must be filled in");
                 break;

             }

             if(myEditField2 == null){
                 errors.setText("Bill Amount must be filled in");
                 break;
             }

             }

            percentageInp = Float.parseFloat(myEditField.getText().toString());
            billAmount = Float.parseFloat(myEditField2.getText().toString());

            percentage = ((float)percentageInp /100);

            output = (double)(billAmount * percentage);

            double result = output * 100;
            result = Math.round(result);
            result = result / 100;

            output1 = Double.toString(result);

            textView.setText(output1 + " $");

        }
    });

    clearButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            percentage = 0;
            output = 0;
            output1 = "";
             TextView textView = null;

            textView.setText("");

            percentageInp = 0;
            billAmount = 0;

            myEditField.setText("");
            myEditField2.setText("");


        }


    });
}
}

here is the logcat… I don’t know where to start on this..

08-01 18:13:41.915: E/AndroidRuntime(30328): FATAL EXCEPTION: main
08-01 18:13:41.915: E/AndroidRuntime(30328): java.lang.RuntimeException: Unable to start activity ComponentInfo{tip.calculator/tip.calculator.TipCalculator}: java.lang.NullPointerException
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.os.Looper.loop(Looper.java:137)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread.main(ActivityThread.java:4507)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at java.lang.reflect.Method.invoke(Method.java:511)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at dalvik.system.NativeStart.main(Native Method)
08-01 18:13:41.915: E/AndroidRuntime(30328): Caused by: java.lang.NullPointerException
08-01 18:13:41.915: E/AndroidRuntime(30328):    at tip.calculator.TipCalculator.onCreate(TipCalculator.java:82)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.Activity.performCreate(Activity.java:4465)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
08-01 18:13:41.915: E/AndroidRuntime(30328):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
08-01 18:13:41.915: E/AndroidRuntime(30328):    ... 11 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-09T01:13:40+00:00Added an answer on June 9, 2026 at 1:13 am
    Caused by: java.lang.NullPointerException
        at tip.calculator.TipCalculator.onCreate(TipCalculator.java:82)
    

    You never initialize clearButton.

    clearButton.setOnClickListener(new OnClickListener() {...}
    

    Addition from Comments

    You need to move this:

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

    To here:

    myEditField = (EditText) findViewById(R.id.percentText);
    enter = (Button)findViewById(R.id.button1);
    myEditField2 = (EditText) findViewById(R.id.billText);
    clearButton = (Button) findViewById(R.id.clearButton);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone kindly suggest what I'm doing wrong here? I'm trying to get the
I just want to know where am i wrong here: import java.io.*; class Tokens{
I have tried to use the example shown here but java showing error message
An example can be found here compass.java . Api here
all files in ~/Cipher/nsdl/crypto can be found here java files compiled with gcj, see
I keep getting this error here: SEVERE: java.lang.NumberFormatException: For input string: at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at
I'm learning Java here, and using a GLabel object. It's in the ACM Graphics
I am trying to connect to SQL Server 2008 server from Java here is
I have this chess engine Rybka.exe, that i have to execute in java Here
The Java tutorials here mention that &= is an assignment operator but doesn't seem

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.