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

The Archive Base Latest Questions

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

I am fairly new to android and am writing an app that will solve

  • 0

I am fairly new to android and am writing an app that will solve physics problems. The math is going well thanks to some help from these forums, but when I try to start my activity from a list it comes up with a nullpointerexception in the onCreate Method of the new activity. This doesn’t seem to make much sense though, because all thats there is a submit button that executes the math from some EditText views. Here is my code.

package android.physicsengine;

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 java.lang.Math;

public class ProjectileMotion extends Activity {

 private EditText acceleration;
 private EditText finalVelocity;
 private EditText initialVelocity;
 private EditText time;
 private EditText deltay;
 private EditText velocity;
 private EditText deltax;
 private Button submitButton;

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

  submitButton.setOnClickListener(new OnClickListener() { 
   @Override
   public void onClick(View v) {
    acceleration = (EditText)findViewById(R.id.acceleration);
    double a = Doublify(acceleration);

    finalVelocity = (EditText)findViewById(R.id.finalVelocity);
    double vf = Doublify(finalVelocity);

    initialVelocity = (EditText)findViewById(R.id.intitialVelocity);
    double vi = Doublify(initialVelocity);

    time = (EditText)findViewById(R.id.time);
    double t = Doublify(time);

    deltay = (EditText)findViewById(R.id.deltay);
    double y = Doublify(deltay);

    velocity = (EditText)findViewById(R.id.velocity);
    double vx = Doublify(velocity);

    deltax = (EditText)findViewById(R.id.deltax);
    double x = Doublify(deltax);


    //Y Axis
    if(time.getText()==null && deltay.getText()==null){
     time.setText(Double.toString((vf-vi)/a));
     deltay.setText(Double.toString(((vf-vi)/a)+(a*Math.pow(((vf-vi)/a),2))));
    }
    if(acceleration.getText()==null && deltay.getText()==null){
     acceleration.setText(Double.toString((vf-vi)/t));
     deltay.setText(Double.toString((vi*t+.5*((vf-vi)/t))*Math.pow(t,2)));
    }
    if(acceleration.getText()==null && time.getText()==null){
     acceleration.setText(Double.toString(((Math.pow(vf,2)-Math.pow(vi,2)))/2*y));
     time.setText(Double.toString(2*y*(vf-vi)/(Math.pow(vf,2)-vi)));
    }
    if(initialVelocity.getText()==null && deltay.getText()==null){
     initialVelocity.setText(Double.toString(vf-a*t));
     deltay.setText(Double.toString((vf-a*t)*t+.5*a*Math.pow(t,2)));
    }
    if(initialVelocity.getText()==null && time.getText()==null){
     initialVelocity.setText(Double.toString(Math.sqrt(Math.pow(vf,2)-2*a*y)));
     time.setText(Double.toString((vf-Math.sqrt(Math.pow(vf,2)-2*a*y))/2));
    }
    if(initialVelocity.getText()==null && acceleration.getText()==null){
     initialVelocity.setText(Double.toString(vf-2*(vf-y/t)));
     acceleration.setText(Double.toString((2/t)*(vf-y/t)));
    }
    if(finalVelocity.getText()==null && deltay.getText()==null){
     finalVelocity.setText(Double.toString(vi+a*t));
     deltay.setText(Double.toString(vi*t+.5*a*Math.pow(t,2)));
    }
    if(finalVelocity.getText()==null && time.getText()==null){
     finalVelocity.setText(Double.toString(Math.sqrt(Math.pow(vi,2)+2*a*y)));
     time.setText(Double.toString(((Math.sqrt(Math.pow(vi,2)+2*a*y)-vi))/a));
    }
    if(finalVelocity.getText()==null && acceleration.getText()==null){
     acceleration.setText(Double.toString(2*(y-vi*t)/Math.pow(t,2)));
     finalVelocity.setText(Double.toString(vi+(2*(y-vi*t)/t)));
    }
    if(finalVelocity.getText()==null && initialVelocity.getText()==null){
     initialVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t));
     finalVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t)+a*t);
    }

   }   

  });

 }
 private double Doublify(EditText editText){
  if(editText.getText()!= null){
   return Double.parseDouble(editText.getText().toString());
  }
  return 0;
 }

}

and the XML

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
   <TableRow>
    <TextView android:text="Projectile Motion Engine"
        android:textSize="25dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_span="4"
        android:layout_gravity="center" />    
   </TableRow>
   <TableRow>
    <TextView android:text="X axis"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_span="2"
        android:textStyle="bold"/>  
    <TextView android:text="Y axis"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_span="2"
        android:textStyle="bold"/>  
   </TableRow>
   <TableRow>
    <TextView android:text="accel(m/s^2)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/acceleration"
        android:text="9.8"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView android:text="deltax(m)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/deltax"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
   </TableRow>
   <TableRow>
    <TextView android:text="init v(m/s)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/intitialVelocity"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView android:text="v ="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/velocity"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
   </TableRow>
   <TableRow>
    <TextView android:text="final v(m/s)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/finalVelocity"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView android:text="time(s)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/time"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
   </TableRow>
   <TableRow>
    <TextView android:text="deltay(m)="
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <EditText android:id="@+id/deltay"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
  <Button android:id="@+id/submitButton"
    android:layout_width="fill_parent"
      android:layout_height="wrap_content" 
      android:layout_span="2"
      android:text="Launch" />
   </TableRow>

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

    Based on the code you’ve posted, it appears that you call
    submitButton.setOnClickListener(new OnClickListener() {
    before instantiating submitButton with a value. This would cause a NullPointer

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

Sidebar

Related Questions

Im fairly new to android dev and I want to build an app that
I'm fairly new to Android/Java and wanted to make an app that displays info
I am fairly new to android and I am creating an app that uses
I'm fairly new to Android developing, and I've been assigned to make an app
Everything will be coming from JSON objects. I'm fairly new to android layouts, what
im fairly new to android development, but i'm having some trouble trying to make
I am fairly new to Android development as well as Java and i am
fairly new Android developer here. I've come across a strange problem that I'm not
I'm fairly new in Android/Java programming, so some of the basic stuff is still
I'm fairly new to developing in Android and I'm not sure how to solve

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.