我有这个应用程序它说当我打开它意外关闭,这里是主要的java ...大部分工作完成了,我真的需要尽可能多的帮助,因为我可以提前谢谢你们/ p>
package geezer.quiz.app;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import geezer.quiz.app.score;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//---------------
final TextView aText;
final TextView bText;
final TextView cText;
final TextView dText;
final TextView question;
final CheckBox a1;
final CheckBox b1;
final CheckBox c1;
final CheckBox d1;
final TextView result;
Button next;
a1 = (CheckBox) findViewById(R.id.checkBox1);
b1 = (CheckBox) findViewById(R.id.checkBox2);
c1 = (CheckBox) findViewById(R.id.checkBox3);
d1 = (CheckBox) findViewById(R.id.checkBox4);
result = (EditText) findViewById(R.id.result);
aText = (EditText) findViewById(R.id.textView1);
bText = (EditText) findViewById(R.id.textView1);
cText = (EditText) findViewById(R.id.textView1);
dText = (EditText) findViewById(R.id.textView1);
question = (EditText)findViewById(R.id.questionText);
next = (Button) findViewById(R.id.button1);
final String a[] = new String[5];
final String b[] = new String[5];
final String c[] = new String[5];
final String d[] = new String[5];
final String questions[]= new String [5];
a[0] = "Bell Bottoms";
a[1] = "Far Out";
a[2] = "Insanity";
a[3] = "Tye Dye";
a[4] = "Yes";
b[0] = "Speedos";
b[1] = "Solid";
b[2] = "Calvin Harris";
b[3] = "Love Beads";
b[4] = "Maybe";
c[0] = "Plaid";
c[1] = "Norm";
c[2] = "Cobra Starship";
c[3] = "Bell Bottoms";
c[4] = "Later";
d[0] = "Flannel";
d[1] = "Radical";
d[2] = "David Guetta";
d[3] = "Granny Glasses";
d[4] = "Never";
questions[0] = "Which is the most in style?";
questions[1] = "Which term is used most?";
questions[2] = "Four musical artists are listed, which is fake?";
questions[3] = "Which of these is the most embarrasing?";
questions[4] = "If someone proposed you join a Golly Gee club how would you respond?";
next.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
score.q ++;
boolean q1a = false;
boolean q1b = false;
boolean q1c = false;
boolean q1d = false;
boolean q2a = false;
boolean q2b = false;
boolean q2c = false;
boolean q2d = false;
boolean q3a = false;
boolean q3b = false;
boolean q3c = false;
boolean q3d = false;
boolean q4a = false;
boolean q4b = false;
boolean q4c = false;
boolean q4d = false;
boolean q5a = false;
boolean q5b = false;
boolean q5c = false;
boolean q5d = false;
aText.setText(a[score.q]);
bText.setText(b[score.q]);
cText.setText(c[score.q]);
dText.setText(d[score.q]);
question.setText(questions[score.q]);
if(d1.isChecked() && score.q == 0) {
q1d = true;
score.score++;
}
if(c1.isChecked() && score.q == 1) {
q2c = true;
score.score++;
}
if(a1.isChecked() && score.q == 2) {
q3a = true;
score.score++;
}
if(d1.isChecked() && score.q == 3) {
q4d = true;
score.score++;
}
if(d1.isChecked() && score.q == 4) {
q5d = true;
score.score++;
if( score.score >2 && score.q == 4){
result.setText("You are not a geezer");
}
if( score.score <3 && score.q == 4){
result.setText("You are indeed a geezer");
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这是第二个java文件(得分)......我这里只有两个变量
package geezer.quiz.app;
import geezer.quiz.app.MainActivity;
public class score {
protected static int score = 0;
protected static int q =-1;
/**
* @param args
*/
public static void main(String[] args) {
}
}
这里是logcat,我不知道这意味着什么...我想提供这个,对不起我忘了......
07-28 23:45:23.542: D/AndroidRuntime(411): Shutting down VM
07-28 23:45:23.542: W/dalvikvm(411): threadid=1: thread exiting with uncaught exception (group=0x40014760)
07-28 23:45:23.576: E/AndroidRuntime(411): FATAL EXCEPTION: main
07-28 23:45:23.576: E/AndroidRuntime(411): java.lang.RuntimeException: Unable to start activity ComponentInfo{geezer.quiz.app/geezer.quiz.app.MainActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread.access$500(ActivityThread.java:122)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.os.Looper.loop(Looper.java:132)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread.main(ActivityThread.java:4123)
07-28 23:45:23.576: E/AndroidRuntime(411): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 23:45:23.576: E/AndroidRuntime(411): at java.lang.reflect.Method.invoke(Method.java:491)
07-28 23:45:23.576: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-28 23:45:23.576: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-28 23:45:23.576: E/AndroidRuntime(411): at dalvik.system.NativeStart.main(Native Method)
07-28 23:45:23.576: E/AndroidRuntime(411): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
07-28 23:45:23.576: E/AndroidRuntime(411): at geezer.quiz.app.MainActivity.onCreate(MainActivity.java:40)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.Activity.performCreate(Activity.java:4397)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
07-28 23:45:23.576: E/AndroidRuntime(411): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
07-28 23:45:23.576: E/AndroidRuntime(411): ... 11 more
07-28 23:46:32.822: I/Process(411): Sending signal. PID: 411 SIG: 9
07-28 23:48:24.712: D/AndroidRuntime(420): Shutting down VM
07-28 23:48:24.722: W/dalvikvm(420): threadid=1: thread exiting with uncaught exception (group=0x40014760)
07-28 23:48:24.742: E/AndroidRuntime(420): FATAL EXCEPTION: main
07-28 23:48:24.742: E/AndroidRuntime(420): java.lang.RuntimeException: Unable to start activity ComponentInfo{geezer.quiz.app/geezer.quiz.app.MainActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread.access$500(ActivityThread.java:122)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.os.Looper.loop(Looper.java:132)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread.main(ActivityThread.java:4123)
07-28 23:48:24.742: E/AndroidRuntime(420): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 23:48:24.742: E/AndroidRuntime(420): at java.lang.reflect.Method.invoke(Method.java:491)
07-28 23:48:24.742: E/AndroidRuntime(420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-28 23:48:24.742: E/AndroidRuntime(420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-28 23:48:24.742: E/AndroidRuntime(420): at dalvik.system.NativeStart.main(Native Method)
07-28 23:48:24.742: E/AndroidRuntime(420): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
07-28 23:48:24.742: E/AndroidRuntime(420): at geezer.quiz.app.MainActivity.onCreate(MainActivity.java:40)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.Activity.performCreate(Activity.java:4397)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
07-28 23:48:24.742: E/AndroidRuntime(420): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
07-28 23:48:24.742: E/AndroidRuntime(420): ... 11 more
答案 0 :(得分:2)
堆栈跟踪告诉您完全问题是什么:
android.widget.TextView cannot be cast to android.widget.EditText
...这意味着其中一个演员表无效,因为您尝试投射到EditText
的视图实际上是TextView
:< / p>
result = (EditText) findViewById(R.id.result);
aText = (EditText) findViewById(R.id.textView1);
bText = (EditText) findViewById(R.id.textView1);
cText = (EditText) findViewById(R.id.textView1);
dText = (EditText) findViewById(R.id.textView1);
question = (EditText)findViewById(R.id.questionText);
再次,在MainActivity.java
第40行,正如堆栈strace告诉你的那样:
07-28 23:45:23.576: E/AndroidRuntime(411): at geezer.quiz.app.MainActivity.onCreate(MainActivity.java:40)