threadid = 1:线程退出,未捕获异常(group = 0x409961f8)

时间:2015-01-11 22:39:13

标签: android

我得到了以下堆栈跟踪,现在搜索了很长时间后,我仍然不知道是什么导致它。相当新的。

我在互联网上找到了大部分代码并对其进行了修改以符合我自己的目的,因此这可能会导致一些问题。

01-11 22:20:02.608: W/dalvikvm(573): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
01-11 22:20:02.628: E/AndroidRuntime(573): FATAL EXCEPTION: main
01-11 22:20:02.628: E/AndroidRuntime(573): java.lang.IllegalStateException: Could not execute method of the activity
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.view.View$1.onClick(View.java:3039)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.view.View.performClick(View.java:3480)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.view.View$PerformClick.run(View.java:13983)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.os.Handler.handleCallback(Handler.java:605)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.os.Looper.loop(Looper.java:137)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.app.ActivityThread.main(ActivityThread.java:4340)
01-11 22:20:02.628: E/AndroidRuntime(573):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 22:20:02.628: E/AndroidRuntime(573):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 22:20:02.628: E/AndroidRuntime(573):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-11 22:20:02.628: E/AndroidRuntime(573):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-11 22:20:02.628: E/AndroidRuntime(573):  at dalvik.system.NativeStart.main(Native Method)
01-11 22:20:02.628: E/AndroidRuntime(573): Caused by: java.lang.reflect.InvocationTargetException
01-11 22:20:02.628: E/AndroidRuntime(573):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 22:20:02.628: E/AndroidRuntime(573):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 22:20:02.628: E/AndroidRuntime(573):  at android.view.View$1.onClick(View.java:3034)
01-11 22:20:02.628: E/AndroidRuntime(573):  ... 11 more
01-11 22:20:02.628: E/AndroidRuntime(573): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to nl.hees.quiz.QuizApplication
01-11 22:20:02.628: E/AndroidRuntime(573):  at nl.hees.quiz.MainActivity.onClick(MainActivity.java:45)
01-11 22:20:02.628: E/AndroidRuntime(573):  ... 14 more

MainActivity.java

public class MainActivity extends Activity {
    private Button tfBtn, mcBtn, sqBtn;

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

        tfBtn = (Button) findViewById(R.id.button1);
        mcBtn = (Button) findViewById(R.id.button2);
        sqBtn = (Button) findViewById(R.id.button3);
    }

    public void onClick(View v) {
        Intent i;

        switch(v.getId()) {
        case R.id.button1:


            i = new Intent(this, TfActivity.class);
            startActivity(i);
            break;
        case R.id.button2:
            //Retrieve questions//
            List<Question> questions = getQuestionsFromDb();

            //Initialize game//
            Game g = new Game();
            g.setQuestions(questions);
            g.setNumRounds(getNumQuestions());
            ((QuizApplication)getApplication()).setCurrentGame(g);

            //Start game//
            i = new Intent(this, McActivity.class);
            startActivity(i);
            break;
        case R.id.button3:


            i = new Intent(this, SqActivity.class);
            startActivity(i);
            break;
        case R.id.button4:
            finish();
            break;
        }
    }

    private List<Question> getQuestionsFromDb() throws Error {
        int diff = getDifficultySettings();
        int numQuestions = getNumQuestions();

        DBHelper helper = new DBHelper(this);
        try {
            helper.createDataBase();
        } catch(IOException ioe) {
            throw new Error("Kan database niet aanmaken");
        }
        try {
            helper.openDataBase();
        } catch(SQLException sqle) {
            throw sqle;
        }
        List<Question> questions = helper.getQuestions(diff, numQuestions);
        helper.close();
        return questions;
    }

    private int getDifficultySettings() {
        SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
        int diff = settings.getInt(Constants.DIFFICULTY, Constants.MEDIUM);
        return diff;
    }

    private int getNumQuestions() {
        SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
        int numRounds = settings.getInt(Constants.NUM_ROUNDS, 20);
        return numRounds;
    }
}

2 个答案:

答案 0 :(得分:0)

我假设您在android:name="nl.hees.quiz.QuizApplication文件的application标记中遗漏了AndroidManifest.xml

答案 1 :(得分:0)

我想,您可能在项目中使用了一些自定义应用程序。在那种情况下,

android:name="com.exercice.ormdatabase.DtoFactory"应包含在Application Tag

中的AndroidManifest.XML文件中

以下提供的样本

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:name="nl.hees.quiz.QuizApplication">
    ......
</application>