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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:14:51+00:00 2026-06-04T15:14:51+00:00

I made a simple car mileage calculator. package com.android.carmanager; import com.android.carmanager.CarManagerActivity; import android.os.Bundle; import

  • 0

I made a simple car mileage calculator.

package com.android.carmanager;

import com.android.carmanager.CarManagerActivity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;


public class MileageCalculator extends CarManagerActivity {
private EditText input1;
private EditText input2;
private EditText input3;
private TextView distance;
private TextView showmileage;


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

        input1 = (EditText) findViewById(R.id.input1);
        input2 = (EditText) findViewById(R.id.input2);
        input3 = (EditText) findViewById(R.id.input3);
        distance = (TextView) findViewById(R.id.distance);
        showmileage = (TextView) findViewById(R.id.showmileage);

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

        double totaldistance = new Double(input2.getText().toString()) - new Double(input1.getText().toString());
        distance.setText(Double.toString(totaldistance));

        calculatebutton.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {

                double result = new Double(distance.getText().toString()) / new Double(input3.getText().toString());
                showmileage.setText(Double.toString(result));

            }

    });


}
}

And the mileagecalculator .xml file is here:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/InitialOdo"
        android:padding="10dp" android:textStyle="bold"/>

    <EditText
        android:id="@+id/input1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:padding="10dp" >


    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/FinalOdo"
        android:padding="10dp" 
        android:textStyle="bold"/>

    <EditText
        android:id="@+id/input2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:padding="10dp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="@string/distance"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/distance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"/>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/fuelrefilled"
        android:padding="10dp" android:textStyle="bold"/>

    <EditText
        android:id="@+id/input3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:padding="10dp" />

    <Button
        android:id="@+id/calculatebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/CalcMileage" />

    <TextView
        android:id="@+id/showmileage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical|center_horizontal" />

</LinearLayout>

Whenever I try to run this simple mileage calculator activity, the app simple crashes returns to the home screen. I encounter the following errors in the log cat.

05-22 17:05:09.743: W/dalvikvm(542): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-22 17:05:09.793: E/AndroidRuntime(542): FATAL EXCEPTION: main
05-22 17:05:09.793: E/AndroidRuntime(542): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.carmanager/com.android.carmanager.MileageCalculator}: java.lang.NumberFormatException: Invalid double: ""
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.os.Looper.loop(Looper.java:137)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.reflect.Method.invokeNative(Native Method)
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.reflect.Method.invoke(Method.java:511)
05-22 17:05:09.793: E/AndroidRuntime(542):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-22 17:05:09.793: E/AndroidRuntime(542):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-22 17:05:09.793: E/AndroidRuntime(542):  at dalvik.system.NativeStart.main(Native Method)
05-22 17:05:09.793: E/AndroidRuntime(542): Caused by: java.lang.NumberFormatException: Invalid double: ""
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.StringToReal.invalidReal(StringToReal.java:63)
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.StringToReal.parseDouble(StringToReal.java:248)
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.Double.parseDouble(Double.java:295)
05-22 17:05:09.793: E/AndroidRuntime(542):  at java.lang.Double.<init>(Double.java:136)
05-22 17:05:09.793: E/AndroidRuntime(542):  at com.android.carmanager.MileageCalculator.onCreate(MileageCalculator.java:30)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.Activity.performCreate(Activity.java:4465)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-22 17:05:09.793: E/AndroidRuntime(542):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-22 17:05:09.793: E/AndroidRuntime(542):  ... 11 more
05-22 17:05:10.033: I/dalvikvm(542): threadid=3: reacting to signal 3
05-22 17:05:10.043: I/dalvikvm(542): Wrote stack traces to '/data/anr/traces.txt'
05-22 17:05:10.493: I/dalvikvm(542): threadid=3: reacting to signal 3
05-22 17:05:10.563: I/dalvikvm(542): Wrote stack traces to '/data/anr/traces.txt'
05-22 17:05:12.313: I/Process(542): Sending signal. PID: 542 SIG: 9

I have restarted the eclipse, avd several times.
Cleaned the build and deleted the R.java File several times, but Still I am stuck here and don’t know what to do next.

  • 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-04T15:14:53+00:00Added an answer on June 4, 2026 at 3:14 pm

    In your OnCreate method, you are calculating a field and are retrieving doubles from the TextViews. Unfortunately, your TextViews are blank and so cannot be converted to a double.

    This is the problem line:

    double totaldistance = new Double(input2.getText().toString()) 
                  - new Double(input1.getText().toString());
    

    You need to either move the calculation to only the button press, do some validation on the data before attempting to calculate, or set some default values.

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

Sidebar

Related Questions

I made a simple calculator and Everytime I hit calculate it'll give a an
i made simple web server like below. import BaseHTTPServer, os, cgi import cgitb; cgitb.enable()
I'm developing simple traffic educational game like https://market.android.com/details?id=cz.allianz.krizovatky.android . When the player taps on
I made simple python program to generate big text file: import sys import random
I made simple web page at http://www.domain.com/mobile/ {rest of url} and i want to
I made simple email in wordpress but it would only send email to the
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
On Windows, testing different OSes is made simple using VMs. Is there a simple
so I'm making some basic programming language (just for exercise). I've made simple grammar
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we

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.