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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:35:49+00:00 2026-06-01T01:35:49+00:00

I am a bit new with android but I have some java experience. So

  • 0

I am a bit new with android but I have some java experience. So I decided to start to make a ‘physics calculator’ just to see if I could make an app after watching a bunch of tutorials on the internet. I have my xml file set up how I want, but all is not on the ‘up and up’. I’ve tried a bunch of things, but I am somewhat lost in what I am doing. Basically, what I want to do with this code is to get what is in the appropriate edit text field(s) and turn them into integers when the appropriate button is pressed, but the application always force closes on my whenever I hit a button (but I am able to ‘see’ all of the graphics such as buttons and such). (For example, for velocity, it would only pull the time and distance since that is all the user supplies). Anyone know what I am doing wrong here?

package t.t.slash25;

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

public class Physics extends Activity implements OnClickListener
{
int v1 , d , t;
EditText velocity, distance , time;
Button calcVel, calcDis, calcTime;
TextView formula, result;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.physics);
        initialize();               
}

private void initialize() 
{
    formula = (TextView) findViewById(R.id.tvFormula);
    velocity = (EditText) findViewById(R.id.etVelocity);
    distance = (EditText) findViewById(R.id.etDistance);
    time = (EditText) findViewById(R.id.etTime);
    calcVel = (Button) findViewById(R.id.bVel);
    calcVel.setOnClickListener(this);
    calcDis = (Button) findViewById(R.id.bDis);
    calcDis.setOnClickListener(this);
    calcTime = (Button) findViewById(R.id.bTime);
    calcTime.setOnClickListener(this);
    result = (TextView) findViewById(R.id.tvResult);
}

public void onClick(View v) 
{

    switch (v.getId()) 
    {
         case R.id.bVel:   //when the button is pressed, convert the editText's to integers, do the formula, and set the text
        d = Integer.getInteger(distance.getText().toString());
        t = Integer.getInteger(time.getText().toString());
        v1 = (d/t);
        result.setText("Velocity = " + v1);
          break;

    }
  }
}

I’m really lost with all of this and I would appreciate any help anyone can give me.

P.S. Here is the logcat error messages:

03-27 15:26:58.959: E/AndroidRuntime(1084): FATAL EXCEPTION: main
03-27 15:26:58.959: E/AndroidRuntime(1084): java.lang.NullPointerException
03-27 15:26:58.959: E/AndroidRuntime(1084):     at t.t.slash25.Physics.onClick(Physics.java:47)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.view.View.performClick(View.java:2532)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.view.View$PerformClick.run(View.java:9277)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.os.Handler.handleCallback(Handler.java:587)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.os.Looper.loop(Looper.java:143)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at android.app.ActivityThread.main(ActivityThread.java:4196)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at java.lang.reflect.Method.invokeNative(Native Method)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at java.lang.reflect.Method.invoke(Method.java:507)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-27 15:26:58.959: E/AndroidRuntime(1084):     at dalvik.system.NativeStart.main(Native Method)

Thanks a bunch!

  • 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-01T01:35:51+00:00Added an answer on June 1, 2026 at 1:35 am

    The problem may be in this two lines:

    d = Integer.getInteger(distance.getText().toString());
    t = Integer.getInteger(time.getText().toString());
    

    The Integer.getInteger() doesn’t converts a String to Integer, you should instead use the Integer.parseInt(), like this:

    d = Integer.parseInt(distance.getText().toString());
    t = Integer.parseInt(time.getText().toString());
    

    See this answer for more details: https://stackoverflow.com/a/3123350/284618

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

Sidebar

Related Questions

I'm pretty new to Android but I have some experience (and a bit rusty
I'm new to programming androids but I have quite a bit of experience programming
I'm a bit new to .Net development, been working in Java for some time
i'm new with Android and i've been playing with it a bit in the
I am a bit new to Perl, but here is what I want to
I'm a bit new to SQL and have trouble constructing a select statement. I
I am brand new to developing for android and have hit something of a
In Android, I have some code to check whether the user has GPS switched
Hello have only a few days with Java and android here. I am a
Firstly, I'm new to Android (so I apologize if this question is ignorant) but

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.