Sunday, May 26, 2019

java - Android studio error: Unfortunately “App” has Stopped





I am new to programming for android, I am developing an application in android studio in which I have to press buttons to enter numbers, like a calculator, my problem is to test the application on a phone in debug mode, when I opened the app is closed immediately by sending this message: Unfortunately "App" has Stopped, I'm using an LG-E425g (Android 4.1.2)



The Main_Activity



    android:id="@+id/LytContenedor"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ingrese"

android:textSize="25sp"
android:layout_weight="0.06"
android:layout_gravity="center_horizontal" />

android:layout_width="345dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_gravity="center_horizontal"
android:inputType="text" />


android:id="@+id/RytContenedor"
android:layout_width="563dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
android:layout_gravity="left">



style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"

android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:height="75dp"

android:width="75dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:textSize="20sp" />


style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button"
android:layout_toEndOf="@+id/button"
android:width="75dp"

android:elegantTextHeight="false"
android:height="75dp"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"

android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2"
android:height="75dp"
android:width="75dp"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:height="75dp"
android:width="75dp"
android:textSize="20sp" />


style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:width="75dp"
android:height="75dp"
android:layout_alignTop="@+id/button4"
android:layout_toLeftOf="@+id/button3"

android:layout_toStartOf="@+id/button3"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:height="75dp"

android:width="75dp"
android:layout_alignTop="@+id/button5"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/button5"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="7"
android:id="@+id/button7"
android:width="75dp"
android:height="75dp"
android:layout_below="@+id/button4"
android:layout_gravity="center_horizontal"
android:layout_toStartOf="@+id/button5"
android:layout_toLeftOf="@+id/button5"
android:textSize="20sp" />


style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:height="75dp"
android:width="75dp"
android:layout_alignTop="@+id/button7"
android:layout_toRightOf="@+id/button7"

android:layout_toEndOf="@+id/button7"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_below="@+id/button5"

android:layout_toRightOf="@+id/button5"
android:layout_alignBottom="@+id/button8"
android:layout_alignRight="@+id/button6"
android:layout_alignEnd="@+id/button6"
android:textSize="20sp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="0"
android:id="@+id/button10"
android:layout_above="@+id/button6"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3"
android:textSize="20sp"
android:width="75dp"
android:height="75dp" />


style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="K"
android:id="@+id/button11"
android:height="75dp"
android:layout_below="@+id/button10"
android:layout_alignLeft="@+id/button10"
android:layout_alignStart="@+id/button10"
android:width="75dp"

android:textSize="20sp" />

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ingresar"
android:id="@+id/button12"
android:layout_toRightOf="@+id/button10"
android:layout_marginLeft="82dp"
android:layout_marginStart="82dp"

android:layout_above="@+id/button9"
android:width="120dp"
android:height="80dp"
android:textSize="20dp" />

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Borrar"

android:id="@+id/button13"
android:textSize="20dp"
android:width="75dp"
android:height="75dp"
android:layout_gravity="right"
android:layout_weight="0.06"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button12"
android:layout_alignEnd="@+id/button12"
android:layout_alignLeft="@+id/button12"

android:layout_alignStart="@+id/button12" />

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/button14"
android:height="75dp"
android:textSize="20dp"
android:width="75dp"

android:layout_below="@+id/button11"
android:layout_toRightOf="@+id/button9"
android:layout_alignRight="@+id/button11"
android:layout_alignEnd="@+id/button11" />









## JAva Class:##
public class Ingreso extends ActionBarActivity {
private EditText Scr;
private ButtonClickListener btnClick;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_ingreso);
Scr =(EditText) findViewById(R.id.editText);

int idList[]={ R.id.button,R.id.button2,R.id.button3,R.id.button4,R.id.button5,R.id.button6,
R.id.button7,R.id.button8,R.id.button9,R.id.button10,R.id.button11,R.id.button14,R.id.button13};

for(int id:idList){
View v = (View) findViewById(id);
v.setOnClickListener(btnClick);
}

}






@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_ingreso, menu);
return true;
}

public void getKeyboard(String Str){
String ScrCurrent= Scr.getText().toString();
ScrCurrent +=Str;
Scr.setText(ScrCurrent);
}


private class ButtonClickListener implements View.OnClickListener{
public void onClick(View v){
switch (v.getId())
{
case R.id.button13:
Scr.setText("");

break;
default:
String numb =((Button) v).getText().toString();

getKeyboard(numb);
break;
}
}
}




@Override

public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}


return super.onOptionsItemSelected(item);
}
}

Answer



You need to use the LogCat and try to find what is causing the app to crash.



If you don't see the LogCat,
Press ALT + 6 if you are using Android Studio.
or
Window - Open Perspective - Other - LogCat if you are using Eclipse.




Go to the LogCat, from the drop down menu select error. This will contain all the required information to help you debug. If that doesn't help, post the LogCat as an edit to your question and somebody will help you out.



Here is something to get you started: Unfortunately MyApp has stopped. How can I solve this?


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...