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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:28:24+00:00 2026-06-13T12:28:24+00:00

I have been spending a little time going over some of Google’s android tutorials,

  • 0

I have been spending a little time going over some of Google’s android tutorials, and decided to throw together my own simple calculator application. I know a good bit of JAVA, and have messed around a little bit of Android back a few SDKs ago. I think the code is fine, but I just can’t get the bastard to run. I have been trying to find an answer based on my LogCat stuff, but have had no luck. First, here is my MainActivity.java:

package com.AppliedArgonautics.calculator;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
    EditText editText1 = (EditText)findViewById(R.id.editText1);
    EditText editText2 = (EditText)findViewById(R.id.editText2);
    TextView textView1 = (TextView)findViewById(R.id.textView1);

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
public void Add(){
    float num1 = Float.parseFloat(editText1.getText().toString());
    float num2 = Float.parseFloat(editText2.getText().toString());
    float result = num1 + num2;
    textView1.setText(Float.toString(result));
}
public void Subtract(){
    float num1 = Float.parseFloat(editText1.getText().toString());
    float num2 = Float.parseFloat(editText2.getText().toString());
    float result = num1 - num2;
    textView1.setText(Float.toString(result));
}
public void Multiply(){
    float num1 = Float.parseFloat(editText1.getText().toString());
    float num2 = Float.parseFloat(editText2.getText().toString());
    float result = num1 * num2;
    textView1.setText(Float.toString(result));
}
public void Divide(){
    float num1 = Float.parseFloat(editText1.getText().toString());
    float num2 = Float.parseFloat(editText2.getText().toString());
    float result = num1 / num2;
    textView1.setText(Float.toString(result));
}
public void Clear(){
    editText1.setText("");
    editText2.setText("");
    textView1.setText("");
}
}

My manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.AppliedArgonautics.calculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

then, the activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="32dp"
        android:onClick="Add"
        android:text="Add" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="45dp"
        android:onClick="Multiply"
        android:text="Multiply" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button3"
        android:layout_alignParentRight="true"
        android:layout_marginRight="28dp"
        android:onClick="Subtract"
        android:text="Subtract" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button3"
        android:layout_alignBottom="@+id/button3"
        android:layout_alignLeft="@+id/button2"
        android:onClick="Divide"
        android:text="Divide" />

     <Button
         android:id="@+id/button5"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/button1"
         android:layout_centerHorizontal="true"
         android:onClick="Clear"
         android:text="Clear" />

     <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/button1"
        android:layout_marginTop="37dp"
        android:ems="10"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/editText1"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/editText1"
        android:ems="10"
        android:inputType="phone" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button5"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="56dp"
        android:text="TextView" />

</RelativeLayout>

This is what LogCat shows when I try to run it:

/Trace   ( 3186): error opening trace file: No such file or directory (2)
D/AndroidRuntime( 3186): Shutting down VM
W/dalvikvm( 3186): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
E/AndroidRuntime( 3186): FATAL EXCEPTION: main
E/AndroidRuntime( 3186): java.lang.RuntimeException: Unable to instantiate activity           ComponentInfo{com.AppliedArgonautics.calculator/com.AppliedArgonautics.calculator.MainActivi    ty}: java.lang.NullPointerException
E/AndroidRuntime( 3186):    at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
E/AndroidRuntime( 3186):    at     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 3186):    at     android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 3186):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 3186):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3186):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3186):    at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 3186):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3186):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3186):    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 3186):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 3186):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3186): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3186):    at android.app.Activity.findViewById(Activity.java:1825)
E/AndroidRuntime( 3186):    at com.AppliedArgonautics.calculator.MainActivity.<init>(MainActivity.java:10)
E/AndroidRuntime( 3186):    at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 3186):    at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime( 3186):    at  android.app.Instrumentation.newActivity(Instrumentation.java:1053)
E/AndroidRuntime( 3186):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
E/AndroidRuntime( 3186):    ... 11 more
W/ActivityManager(  160):   Force finishing activity com.AppliedArgonautics.calculator/.MainActivity

I would really appreciate it if someone could have a look at this. I thought it would be cool to learn android, but am getting very frustrated with my inability to get even a simple program like this to launch. Thank you.

  • 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-13T12:28:25+00:00Added an answer on June 13, 2026 at 12:28 pm

    There may be lot of issues in your code, but first to get you started:

    Create EditText and TextView as instance variables. Assign views to those variables in onCreate.

    public class MainActivity extends Activity {
            EditText editText1;
            EditText editText2;
            TextView textView1;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
         editText1 = (EditText)findViewById(R.id.editText1);
         editText2 = (EditText)findViewById(R.id.editText2);
         textView1 = (TextView)findViewById(R.id.textView1);
        }
    .........
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been spending some time on this. My problem involves bringing back domain
I have been spending some time playing with Clojure-CLR. My REPL is working, I
I have been spending some time in debugging a programme which gives segmentation fault.
In a Ruby project that I have been spending some time on lately, I
I have little problem that I have been trying to solve for some time.
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
So i've been spending some time developing an iPhone app - it's a simple
I have a JQuery code I have been using for some time however today
I have been spending a lot of time on knowing the way to use
I have been spending time learning how to use the iPhone SDK. I've read

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.