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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:32:41+00:00 2026-05-20T00:32:41+00:00

I am getting a java.lang.NullPointerException error on line 41 (setText) when I execute the

  • 0

I am getting a java.lang.NullPointerException error on line 41 (setText) when I execute the following code.

I have seen EditText boxes being set with this line before and I do not understand what I am doing wrong.

I have no experience with eclipse or java but I am trying to learn. Please help!

Code:

package Psychrometric.Calculator;

import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.text.TextUtils;
import android.os.Bundle;

public class Calculator extends Activity {

private EditText altitude;
private EditText barometricPressure;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
           setContentView(R.layout.main);

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

    calcButton.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {        

            altitude = (EditText) findViewById(R.id.altitude);


            if (altitude.getText().length() != 0) 
            {

                double altitudeDouble = new Double(altitude.getText().toString());     

                double barometricPressureDouble = 29.92 * java.lang.Math.pow((1 - 0.0000068753 * altitudeDouble), 5.259); 

                altitude.setText(Double.toString(altitudeDouble));
                barometricPressure.setText(Double.toString(barometricPressureDouble));

            }

    }

   });

   }

   }

XML:
<?xml version="1.0" encoding="utf-8"?>

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
>

<TableLayout
android:id="@+id/widget27"
android:layout_width="320px"
android:layout_height="825px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:stretchColumns="1"
>

<TableRow
android:id="@+id/firstRow"
android:layout_width="fill_parent"
android:layout_height="75px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>

<Button
android:id="@+id/calcButton"
android:layout_width="185px"
android:layout_height="75px"
android:text="Calculate"
>
</Button>
</TableRow>

<TableRow
android:id="@+id/widget45"
android:layout_width="fill_parent"
android:layout_height="50px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>


<TextView
android:id="@+id/widget221"
android:layout_width="wrap_content"
android:layout_height="50px"
android:text="Altitude"
>
</TextView>
<EditText
android:id="@+id/altitude"
android:layout_width="wrap_content"
android:layout_height="50px"
android:textSize="18sp"
android:numeric="decimal"
>
</EditText>
<TextView
android:id="@+id/widget454"
android:layout_width="wrap_content"
android:layout_height="50px"
android:text="ft"
>
</TextView>
</TableRow>
<TableRow
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="50px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>
<TextView
android:id="@+id/widget222"
android:layout_width="wrap_content"
android:layout_height="50px"
android:text="Barometric Pressure"
>
</TextView>
<EditText
android:id="@+id/barometricPressure"
android:layout_width="wrap_content"
android:layout_height="50px"
android:textSize="18sp"
android:numeric="decimal"
>
</EditText>
<TextView
android:id="@+id/widget455"
android:layout_width="wrap_content"
android:layout_height="50px"
android:text="in. Hg"
>
</TextView>
</TableRow>
</TableLayout>
</ScrollView>

LogCat:
02-11 12:49:02.334: DEBUG/AndroidRuntime(11161): Shutting down VM

02-11 12:49:02.334: WARN/dalvikvm(11161): threadid=1: thread exiting with uncaught exception (group=0x400259f8)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161): FATAL EXCEPTION: main

02-11 12:49:02.394: ERROR/AndroidRuntime(11161): java.lang.NullPointerException

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at Psychrometric.Calculator.Calculator$1.onClick(Calculator.java:41)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.view.View.performClick(View.java:2408)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.view.View$PerformClick.run(View.java:8817)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.os.Handler.handleCallback(Handler.java:587)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.os.Handler.dispatchMessage(Handler.java:92)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.os.Looper.loop(Looper.java:144)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at android.app.ActivityThread.main(ActivityThread.java:4937)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at java.lang.reflect.Method.invokeNative(Native Method)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at java.lang.reflect.Method.invoke(Method.java:521)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

02-11 12:49:02.394: ERROR/AndroidRuntime(11161):     at dalvik.system.NativeStart.main(Native Method)

02-11 12:49:02.404: WARN/ActivityManager(220):   Force finishing activity Psychrometric.Calculator/.Calculator
  • 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-20T00:32:42+00:00Added an answer on May 20, 2026 at 12:32 am

    You haven’t assigned to barometricPressure – it is still null.

    For altitude you have

    altitude = (EditText) findViewById(R.id.altitude);
    

    Presumably you need something similar for barometricPressure too.

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

Sidebar

Related Questions

Getting the following error : java.lang.NullPointerException: Module 'null' not found. <?xml version=1.0 encoding=UTF-8 ?>
I am getting this error when i use a string array java.lang.NullPointerException The code
We're getting this error java.lang.NullPointerException at java.util.ArrayList.<init>(Unknown Source) at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38) where ExtendedArrayList:38 is new
I'm getting a NullPointerException in the following Hibernate code. I've marked the line with
Multi-Test TestNG.xml file results in java.lang.NullPointerException Hello Quality Team, I need help getting TestNG
First off, this is the error I am getting java.lang.OutOfMemoryError at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56) at coderaustin.com.Main.onCreate(Main.java:41)
I am getting the error: 05-14 15:06:13.124: ERROR/AndroidRuntime(2218): Caused by: java.lang.RuntimeException: Could not create
I keep getting Activity Monitor Job. java.lang.NullPointerException while working with Eclipse 3.6 Has anybody
I have a problem with a junit ant build, i'm getting a java.lang.OutOfMemoryError: PermGen
I'm getting a NoSuchMethodError error when running my Java program. What's wrong and how

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.