Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android threadid=1:线程退出时出现未捕获异常(组=0x409961f8)_Android - Fatal编程技术网

Android threadid=1:线程退出时出现未捕获异常(组=0x409961f8)

Android threadid=1:线程退出时出现未捕获异常(组=0x409961f8),android,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 EXCEPT

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

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

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;
    }
}
公共类MainActivity扩展活动{
专用按钮tfBtn、mcBtn、sqBtn;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tfBtn=(按钮)findViewById(R.id.button1);
mcBtn=(按钮)findViewById(R.id.button2);
sqBtn=(按钮)findViewById(R.id.button3);
}
公共void onClick(视图v){
意图一;
开关(v.getId()){
案例R.id.button1:
i=新意图(此,TfActivity.class);
星触觉(i);
打破
案例R.id.按钮2:
//检索问题//
列出问题=getQuestionsFromDb();
//初始化游戏//
游戏g=新游戏();
g、 设置问题;
g、 setNumRounds(getNumQuestions());
((QuizApplication)getApplication()).setCurrentGame(g);
//开始比赛//
i=新意图(此,McActivity.class);
星触觉(i);
打破
外壳R.id.按钮3:
i=新意图(本,SqActivity.class);
星触觉(i);
打破
外壳R.id.按钮4:
完成();
打破
}
}
私有列表getQuestionsFromDb()引发错误{
int diff=getDifficultySettings();
int numQuestions=getNumQuestions();
DBHelper=newdbhelper(this);
试一试{
createDataBase();
}捕获(ioe异常ioe){
抛出新错误(“Kan数据库niet aanmaken”);
}
试一试{
openDataBase();
}捕获(SQLException sqle){
抛出sqle;
}
列出问题=helper.getQuestions(diff,numQuestions);
helper.close();
回答问题;
}
私有int getDifficultySettings(){
SharedReferences设置=GetSharedReferences(Constants.settings,0);
int diff=settings.getInt(Constants.diff,Constants.MEDIUM);
返回差;
}
私有int getNumQuestions(){
SharedReferences设置=GetSharedReferences(Constants.settings,0);
int numRounds=settings.getInt(Constants.NUM_ROUNDS,20);
返回numRounds;
}
}

我假设您在
AndroidManifest.xml
文件中的
应用程序
标记中缺少
android:name=“nl.hees.quick.quizaApplication

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

android:name=“com.exercice.ormdatabase.dtofacory”
应包含在应用程序标记中的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>

......

@user3481441,请发布堆栈跟踪