Android : program stopped working in android Emulator

on Friday, March 20, 2015


I have a question that I don't Know if it is a suitable place for asking it so I will be thankful you introduce me a site or forum ...


I have written the program of calculator for android in Eclipse and no error was appeared while I was completing the codes but when the Emulator is running and for example entering two numbers to sum when the equation operator has clicked,this error appear "unfortunately app has stopped"


my Main.java





package com.Tools.s01_e07;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;



public class Main extends Activity {

private TextView show;
private ImageView n1;
private ImageView n2;
private ImageView n3;
private ImageView n4;
private ImageView n5;
private ImageView n6;
private ImageView n7;
private ImageView n8;
private ImageView n9;
private ImageView n0;

private ImageView nf1;
private ImageView nf2;
private ImageView nf3;
private ImageView nf4;
private ImageView nf5;
private ImageView nf6;

private int V1;
private String F;
private int V2;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

n1=(ImageView) findViewById(R.id.n1);
n2=(ImageView) findViewById(R.id.n2);
n3=(ImageView) findViewById(R.id.n3);
n4=(ImageView) findViewById(R.id.n4);
n5=(ImageView) findViewById(R.id.n5);
n6=(ImageView) findViewById(R.id.n6);
n7=(ImageView) findViewById(R.id.n7);
n8=(ImageView) findViewById(R.id.n8);
n9=(ImageView) findViewById(R.id.n9);
n0=(ImageView) findViewById(R.id.n0);

nf1=(ImageView) findViewById(R.id.nf1);
nf2=(ImageView) findViewById(R.id.nf2);
nf3=(ImageView) findViewById(R.id.nf3);
nf4=(ImageView) findViewById(R.id.nf4);
nf5=(ImageView) findViewById(R.id.nf5);
nf6=(ImageView) findViewById(R.id.nf6);
show=(TextView) findViewById(R.id.show);

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

show.setText(show.getText()+"1");
}
});

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

show.setText(show.getText()+"2");
}
});

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

show.setText(show.getText()+"3");
}
});

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

show.setText(show.getText()+"4");
}
});

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

show.setText(show.getText()+"5");
}
});

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

show.setText(show.getText()+"6");
}
});

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

show.setText(show.getText()+"7");
}
});

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

show.setText(show.getText()+"8");
}
});

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

show.setText(show.getText()+"9");
}
});

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

show.setText(show.getText()+"0");
}
});

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

V1=Integer.parseInt(show.getText().toString());
F="+";
show.setText(" ");
}
});

nf2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
V1=Integer.parseInt(show.getText().toString());
F="-";
show.setText(" ");

}
});

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

V1=Integer.parseInt(show.getText().toString());
F="*";
show.setText(" ");
}
});

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

V1=Integer.parseInt(show.getText().toString());
F="/";
show.setText(" ");
}
});

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

if(F!="" && show.getText().toString()!="")
{
int res=0;
V2=Integer.parseInt(show.getText().toString());
if(F=="+"){

res=V1+V2;
}
if(F=="-"){

res=V1-V2;
}
if(F=="*"){

res=V1*V2;
}
if(F=="/"){

res=V1/V2;

}

show.setText(res+"");
}
}
});

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

}
});

}




}



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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.Tools.s01_e07.Main" >

<ImageView
android:id="@+id/n1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="116dp"
android:layout_marginLeft="64dp"
android:src="@drawable/a01" />

<ImageView
android:id="@+id/n2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/n1"
android:layout_toRightOf="@+id/n1"
android:src="@drawable/a02" />

<ImageView
android:id="@+id/n3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/n2"
android:layout_toRightOf="@+id/n2"
android:src="@drawable/a03" />

<ImageView
android:id="@+id/n4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/n1"
android:layout_alignLeft="@+id/n1"
android:src="@drawable/a04" />

<ImageView
android:id="@+id/n5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/n1"
android:layout_toRightOf="@+id/n1"
android:src="@drawable/a05" />

<ImageView
android:id="@+id/n6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/n3"
android:layout_alignTop="@+id/n5"
android:src="@drawable/a06" />

<ImageView
android:id="@+id/n7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/n4"
android:layout_alignLeft="@+id/n4"
android:src="@drawable/a07" />

<ImageView
android:id="@+id/n8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/n7"
android:layout_toRightOf="@+id/n7"
android:src="@drawable/a08" />

<ImageView
android:id="@+id/n9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/n6"
android:layout_alignTop="@+id/n8"
android:src="@drawable/a09" />

<ImageView
android:id="@+id/n0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/n2"
android:layout_toRightOf="@+id/n1"
android:src="@drawable/a00" />

<ImageView
android:id="@+id/nf5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/n2"
android:layout_toRightOf="@+id/n2"
android:src="@drawable/mosavi" />

<ImageView
android:id="@+id/nf1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/n9"
android:layout_toRightOf="@+id/n9"
android:src="@drawable/sum" />

<ImageView
android:id="@+id/nf2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/nf1"
android:layout_below="@+id/nf1"
android:src="@drawable/tafrigh" />

<ImageView
android:id="@+id/nf3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/nf2"
android:layout_toRightOf="@+id/n3"
android:src="@drawable/zarb" />

<ImageView
android:id="@+id/nf4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/nf3"
android:layout_below="@+id/nf3"
android:src="@drawable/taghsim" />

<ImageView
android:id="@+id/nf6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/n1"
android:layout_alignTop="@+id/nf4"
android:src="@drawable/p2" />

<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/n7"
android:layout_alignLeft="@+id/n7"
android:layout_alignRight="@+id/nf1"
android:layout_marginBottom="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22sp" />

</RelativeLayout>



thanks in advanced....


0 comments:

Post a Comment