
error al ejecutar la aplicacion en el emulador
Publicado por liantony (5 intervenciones) el 26/03/2017 04:26:44
hola estoy haciendo una aplicacion sensilla resulta ser que me tope con un problema con un spinner y un switch , resulta ser que para lo que quiero que haga esa activity hace que el app se cierre
ese es el codigo que estoy usando el error de que se detiene la aplicacion sale cuando inserto las siguentes lineas de codigo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class SenoCosenoTangente extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
EditText ca,
co,
a,
h;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seno_coseno_tangente);
ca = (EditText)findViewById(R.id.cateto_acyasente);
co = (EditText)findViewById(R.id.cateto_opuesto);
a = (EditText)findViewById(R.id.angulo);
h = (EditText)findViewById(R.id.hipotenusa);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
List<String> funciones = new ArrayList<String>();
funciones.add("sin");
funciones.add("cos");
funciones.add("tang");
ArrayAdapter <String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item , funciones);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
double c_o = Integer.parseInt(co.getText().toString());
double c_a = Integer.parseInt(ca.getText().toString());
double hip = Integer.parseInt(h.getText().toString());
switch (position){
case 0 :
Toast.makeText(getApplicationContext(), "sin = " + (c_o/hip) , Toast.LENGTH_LONG ).show();
break;
case 1 :
Toast.makeText(getApplicationContext(), "cos = " + (c_a/hip) , Toast.LENGTH_LONG ).show();
break;
case 2 :
Toast.makeText(getApplicationContext(), "tang = " + (c_a/ c_o), Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
ese es el codigo que estoy usando el error de que se detiene la aplicacion sale cuando inserto las siguentes lineas de codigo
1
2
3
4
double c_o = Integer.parseInt(co.getText().toString());
double c_a = Integer.parseInt(ca.getText().toString());
double hip = Integer.parseInt(h.getText().toString());
Valora esta pregunta


0