I'm new to android development, this is just my second app i built just to kill time, though, i could'nt understand, what caused this error. Need expert advice


The activity_starting_point.xml:



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".StatingPoint" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="35dp"
android:text="Enter Number 1"
android:id="@+id/tvDisplay"
/>

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >

<requestFocus />
</EditText>

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="35dp"
android:text="Enter Number 2"
android:id="@+id/tvDisplay"
/>

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />

<Button
android:id="@+id/button1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Add"
android:layout_gravity="center" />

<Button
android:id="@+id/button1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Subtract"
android:layout_gravity="center" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Your Total is 0 "
android:textSize="45dp"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/tvDisplay" />

</LinearLayout>


The Java class file: StartingPoint.java package com.ankur.calulator;



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


public class StatingPoint extends Activity {


int num1,num2;
int total;
Button add,sub;
TextView display;
EditText no1,no2;



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

total=0;
no1=(EditText) findViewById(R.id.editText1);
no2=(EditText) findViewById(R.id.editText2);
display=(TextView)findViewById(R.id.tvDisplay);

add.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

total=num1+num2;
display.setText("Your Total is "+total);

}
});

sub.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

total=num1-num2;
display.setText("Your Total is "+total);

}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_stating_point, menu);
return true;
}

}


The logcat file: its got blank, i think i messed up with it, though i saw something as java null pointer exception before i knw i'm close, just nt able to find some missing link, need advice.


No comments:

Post a Comment