"Unfurtunately, Stealth has stopped" FATAL EXCEPTION: main

Asked

Viewed 45 times

0

Whatever amendment I make, I still have no solution to this problem. The android Emulator keeps appearing to msg "Unfurtunately, Stealth has stopped". Being that in Main does not present any error, but in the execution of FATAL EXCEPTION: main. All the variavas are declared correctly. I ask you kindly to shed some light on this. Below I have the xml and the . java.

package com.example.stealth2017;

import android.app.Activity;
import android.app.AlertDialog;
//import android.content.Intent;
import android.os.Bundle;
//import android.view.Menu;
//import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Stealth2017MainActivity extends Activity {

    EditText editTextComprimento;
    EditText editTextLargura;
    EditText editTextAltura;

    TextView TextFieldComprimento;
    TextView TextFieldRLargura;
    TextView TextFieldRAltura;

    Button buttonVerificarMedidas;
    Button buttonCalculaAV;
    EditText editTextArea;
    EditText editTextVolume;

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

        final AlertDialog.Builder alerta = new AlertDialog.Builder(Stealth2017MainActivity.this);

        editTextComprimento = (EditText) findViewById(R.id.EditTextComprimento);
        editTextLargura = (EditText) findViewById(R.id.EditTextLargura);
        editTextAltura = (EditText) findViewById(R.id.EditTextAltura);
        editTextArea = (EditText) findViewById(R.id.editTextArea);
        editTextVolume = (EditText) findViewById(R.id.editTextVolume);

        buttonCalculaAV = (Button) findViewById(R.id.buttonCalculaAV);
        buttonVerificarMedidas = (Button) findViewById(R.id.buttonVerificarMedidas);

        TextFieldComprimento = (TextView) findViewById(R.id.TextFieldComprimento);
        TextFieldRLargura = (TextView) findViewById(R.id.TextFieldLargura);
        TextFieldRAltura = (TextView) findViewById(R.id.TextFieldAltura);


        buttonVerificarMedidas.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {


                    double Altura, Comprimento, Largura;

                    Altura = Double.parseDouble(editTextAltura.getText().toString());
                    Comprimento = Double.parseDouble(editTextComprimento.getText().toString());
                    Largura = Double.parseDouble(editTextLargura.getText().toString());


                    if (Comprimento >= 3.0) {
                        editTextComprimento.setText(String.valueOf(Comprimento));
                    } else {
                        alerta.setTitle("Atenção");
                        alerta.setMessage("Comprimento mínimo 3 metros !");
                        alerta.setNeutralButton("OK", null);
                        alerta.show();
                        editTextComprimento.setText("");
                    }


                    if (Altura >= 3.5) {
                        editTextAltura.setText(String.valueOf(Altura));
                    } else {
                        alerta.setTitle("Atenção");
                        alerta.setMessage("Altura mínima 3.5 metros !");
                        alerta.setNeutralButton("OK", null);
                        alerta.show();
                        editTextAltura.setText("");
                    }


                    if (Largura >= 3.0) {
                        editTextLargura.setText(String.valueOf(Largura));
                    } else {
                        alerta.setTitle("Atenção");
                        alerta.setMessage("Largura mínima 3 metros !");
                        alerta.setNeutralButton("OK", null);
                        alerta.show();
                        editTextLargura.setText("");
                    }
                    buttonCalculaAV.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            double Altura, Comprimento, Largura, Area, Volume;

                            Altura = Double.parseDouble(editTextAltura.getText().toString());
                            Comprimento = Double.parseDouble(editTextComprimento.getText().toString());
                            Largura = Double.parseDouble(editTextLargura.getText().toString());

                            if (Largura >= 3.0 && Altura >= 3.5 && Comprimento >= 3.0){

                                Area = Comprimento * Altura; 
                                Volume = Comprimento * Altura * Largura;

                            if (Area >= 10.5) {
                                 Volume = Double.parseDouble(editTextVolume.getText().toString());
                                    Area = Double.parseDouble(editTextArea.getText().toString());
                                editTextArea.setText(String.format("%1$.2f", Area));
                                 //editTextArea.setText(String.valueOf(Area));
                                editTextVolume.setText(String.format("%1$.2f", Volume));
                                 //editTextVolume.setText(String.valueOf(Volume));
                            } else {
                                alerta.setTitle("Atenção");
                                alerta.setMessage("Área mínima 10.5 metros² !");
                                alerta.setNeutralButton("OK", null);
                                alerta.show();
                                editTextArea.setText("");
                                editTextVolume.setText("");
                                editTextComprimento.setText("");
                                editTextLargura.setText("");
                                editTextAltura.setText("");
                            }
                            }                        
                    }
                        });
                };

        });

    }
}

<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"
    tools:context="${relativePackage}.${activityClass}" >

    <LinearLayout
        android:id="@+id/LinearLayoutAltura"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LinearLayoutComprimento" >

        <TextView
            android:id="@+id/TextFieldAltura"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Altura: " />

        <EditText
            android:id="@+id/EditTextAltura"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutLargura"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LinearLayoutAltura" >

        <TextView
            android:id="@+id/TextFieldLargura"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Largura: " />

        <EditText
            android:id="@+id/EditTextLargura"
            android:layout_width="78dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.99"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutComprimento"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="34dp" >

        <TextView
            android:id="@+id/TextFieldComprimento"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Comprimento: " />

        <EditText
            android:id="@+id/EditTextComprimento"
            android:layout_width="118dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.42"
            android:ems="10" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutTecnicos"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LinearLayoutLargura"
        android:layout_marginTop="115dp" >

        <TextView
            android:id="@+id/TextFieldTecnicos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Qtd. Técnicos: " />

        <EditText
            android:id="@+id/EditTextTecnicos"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.16"
            android:ems="10"
            android:focusable="false"
            android:focusableInTouchMode="false" />

        <Button
            android:id="@+id/ButtonTecnicos"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:text="Confirmar" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutMainframes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LinearLayoutTecnicos"
        android:gravity="center" >

        <TextView
            android:id="@+id/TextFieldMainframes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Qtd. Mainframes: " />

        <EditText
            android:id="@+id/EditTextMainframes"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" />

        <Button
            android:id="@+id/ButtonMainframes"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:text="Confirmar" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutCalcular"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/LinearLayoutLargura"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="54dp"
        android:gravity="center" >

        <Button
            android:id="@+id/buttonCalculaAV"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:minWidth="48dp"
            android:text="Calcular medidas"
            android:textSize="12sp" />

        <EditText
            android:id="@+id/editTextArea"
            android:layout_width="62dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Área" />

        <EditText
            android:id="@+id/editTextVolume"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Volume" />
    </LinearLayout>

    <Button
        android:id="@+id/buttonVerificarMedidas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/LinearLayoutLargura"
        android:layout_centerHorizontal="true"
        android:text="Verificar medidas" />

</RelativeLayout>
  • 2

    It would be interesting to put the stacktrace that appears in the logcat, so you could find out what the problem is.

1 answer

1


Without testing and looking closely at your code, it looks like you’re delegating buttonCalculaAV.setOnClickListener() inside buttonVerificarMedidas.setOnClickListener().

Place buttonCalculaAV.setOnClickListener() out of buttonVerificarMedidas.setOnClickListener(), but within the OnCreate().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.