Java 无法解决android中的错误?

Java 无法解决android中的错误?,java,android,android-intent,runtime-error,android-logcat,Java,Android,Android Intent,Runtime Error,Android Logcat,我正在开发android问答游戏。QuestionActivity和EndgameActivity是我游戏中的两个类。我想当我的游戏控制权转移到EndgameActivity时。对于这个问题,我添加了activty类 Intent i = new Intent(this, EndgameActivity.class); startActivity(i); finish(); 在if(currentGame.isGameOver())方法中。但在回

我正在开发android问答游戏。QuestionActivity和EndgameActivity是我游戏中的两个类。我想当我的游戏控制权转移到EndgameActivity时。对于这个问题,我添加了activty类

Intent i = new Intent(this, EndgameActivity.class);
            startActivity(i);
            finish();
if(currentGame.isGameOver())
方法中。但在回答了最后一个问题后,我的游戏控制权没有转移到EndgameActivity,并且记录cat显示以下错误

问题活动课-

public class QuestionActivity extends Activity implements OnClickListener{

    private Question currentQ;
    private GamePlay currentGame;
    private CountDownTimer counterTimer;

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.question);
                processScreen();
         }
                /**
         * Configure current game and get question
         */
         private void processScreen()
         {
        currentGame = ((CYKApplication)getApplication()).getCurrentGame();
        currentQ = currentGame.getNextQuestion();
        Button nextBtn1 = (Button) findViewById(R.id.answer1);
        nextBtn1.setOnClickListener(this);
        Button nextBtn2 = (Button) findViewById(R.id.answer2);
        nextBtn2.setOnClickListener(this);
        Button nextBtn3 = (Button) findViewById(R.id.answer3);
        nextBtn3.setOnClickListener(this);
        Button nextBtn4 = (Button) findViewById(R.id.answer4);
        nextBtn4.setOnClickListener(this);
        Button nextBtn5 = (Button) findViewById(R.id.answer5);
        nextBtn5.setOnClickListener(this);
        /**
         * Update the question and answer options..
         */
        setQuestions();

    }


    /**
     * Method to set the text for the question and answers from the current games
     * current question
     */
    private void setQuestions() {
        //set the question text from current question
        String question = Utility.capitalise(currentQ.getQuestion());
        TextView qText = (TextView) findViewById(R.id.question);
        qText.setText(question);

        //set the available options
        List<String> answers = currentQ.getQuestionOptions();
        TextView option1 = (TextView) findViewById(R.id.answer1);
        option1.setText(Utility.capitalise(answers.get(0)));

        TextView option2 = (TextView) findViewById(R.id.answer2);
        option2.setText(Utility.capitalise(answers.get(1)));

        TextView option3 = (TextView) findViewById(R.id.answer3);
        option3.setText(Utility.capitalise(answers.get(2)));

        TextView option4 = (TextView) findViewById(R.id.answer4);
        option4.setText(Utility.capitalise(answers.get(3)));

        int score = currentGame.getScore();
        String scr = String.valueOf(score);
        TextView score1 = (TextView) findViewById(R.id.score);
        score1.setText(scr);

        counterTimer=new CountDownTimer(15000, 1000) {
            public void onFinish() {                
                if(currentGame.getRound()==20)
                    System.exit(0);
                currentGame.decrementScore1();
                processScreen();
                             }

            public void onTick(long millisUntilFinished) {
                TextView time = (TextView) findViewById(R.id.timers);
                time.setText( ""+millisUntilFinished/1000);
                                }
        };
        counterTimer.start();
    }


    @Override
    public void onResume() {
        super.onResume();
    }


    @Override
    public void onClick(View arg0) {
        //Log.d("Questions", "Moving to next question");
        if(arg0.getId()==R.id.answer5)
        {
        new AlertDialog.Builder(this)
        .setMessage("Are you sure?")
        .setCancelable(true)
        .setPositiveButton("Yes",
         new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
         int id) {
                finish();
                 }
             }).setNegativeButton("No", null).show();

                }

        else
        {
            if(!checkAnswer(arg0)) return;  

        /**
         * check if end of game
         */
        if (currentGame.isGameOver()){
            //Log.d("Questions", "End of game! lets add up the scores..");
            //Log.d("Questions", "Questions Correct: " + currentGame.getRight());
            //Log.d("Questions", "Questions Wrong: " + currentGame.getWrong());
            Intent i = new Intent(this, EndgameActivity.class);
            startActivity(i);
            finish();
        }
            else
            {
            Intent i = new Intent(this, QuestionActivity.class);
                        finish();
                        startActivity(i);
        }
        }
      }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        switch (keyCode)
        {
        case KeyEvent.KEYCODE_BACK :
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }


    /**
     * Check if a checkbox has been selected, and if it
     * has then check if its correct and update gamescore
     */
    private boolean checkAnswer(View v) {

        Button b = (Button) v;
        String answer = b.getText().toString();
         counterTimer.cancel();
         b.setBackgroundResource(R.drawable.ans);
         b.setEnabled(false);
                    //Log.d("Questions", "Valid Checkbox selection made - check if correct");
            if (currentQ.getAnswer().equalsIgnoreCase(answer))
            {
                b.setBackgroundResource(R.drawable.ansgreen);
                //Log.d("Questions", "Correct Answer!");
                currentGame.incrementScore();
            }
            else{
                b.setBackgroundResource(R.drawable.ansred);
                //Log.d("Questions", "Incorrect Answer!");
                currentGame.decrementScore();
            }
            return true;
        }

}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class EndgameActivity extends Activity implements View.OnClickListener{
    Button menue1, adde1;
    TextView escore1;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(findViewById(R.layout.endgame));
        menue1 = (Button) findViewById (R.id.menue);
        menue1.setOnClickListener(this);
        adde1 = (Button) findViewById(R.id.adde);
        adde1.setOnClickListener(this); 
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        switch (keyCode)
        {
        case KeyEvent.KEYCODE_BACK :
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }


         @Override
         public void onClick(View v) {
             switch(v.getId()){
                 case R.id.menue:
                     Intent i= new Intent(this, SplashActivity.class);
                     startActivity(i);    
                     break;
                 case R.id.adde:
                     Intent j = new Intent(this, HighscoreActivity.class);
                     startActivity(j);                   
                 break;

             }
         }

    }
原木猫-

   09-09 18:32:14.668: D/AndroidRuntime(7617): Shutting down VM
09-09 18:32:14.668: W/dalvikvm(7617): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-09 18:32:14.688: E/AndroidRuntime(7617): FATAL EXCEPTION: main
09-09 18:32:14.688: E/AndroidRuntime(7617): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=EndgameActivity }
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Activity.startActivityForResult(Activity.java:3370)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Activity.startActivityForResult(Activity.java:3331)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Activity.startActivity(Activity.java:3566)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.Activity.startActivity(Activity.java:3534)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at com.abc.cyk.QuestionActivity.onClick(QuestionActivity.java:143)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.view.View.performClick(View.java:4204)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.view.View$PerformClick.run(View.java:17355)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.os.Handler.handleCallback(Handler.java:725)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.os.Looper.loop(Looper.java:137)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at java.lang.reflect.Method.invokeNative(Native Method)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at java.lang.reflect.Method.invoke(Method.java:511)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-09 18:32:14.688: E/AndroidRuntime(7617):     at dalvik.system.NativeStart.main(Native Method)
09-09 18:32:18.258: I/Process(7617): Sending signal. PID: 7617 SIG: 9
09-09 18:32:18.758: E/Trace(7693): error opening trace file: No such file or directory (2)
09-09 18:32:18.908: D/dalvikvm(7693): GC_FOR_ALLOC freed 58K, 8% free 2413K/2616K, paused 26ms, total 27ms
09-09 18:32:18.918: I/dalvikvm-heap(7693): Grow heap (frag case) to 4.553MB for 2160016-byte allocation
09-09 18:32:19.038: D/dalvikvm(7693): GC_FOR_ALLOC freed 1K, 5% free 4521K/4728K, paused 113ms, total 113ms
09-09 18:32:19.088: D/dalvikvm(7693): GC_CONCURRENT freed <1K, 5% free 4521K/4728K, paused 4ms+3ms, total 50ms
09-09 18:32:19.558: D/gralloc_goldfish(7693): Emulator without GPU emulation detected.
09-09 18:32:21.728: I/Choreographer(7693): Skipped 71 frames!  The application may be doing too much work on its main thread. 
09-09 18:32:14.668:D/AndroidRuntime(7617):关闭虚拟机
09-09 18:32:14.668:W/dalvikvm(7617):threadid=1:线程以未捕获异常退出(组=0x40a71930)
09-09 18:32:14.688:E/AndroidRuntime(7617):致命异常:主
09-09 18:32:14.688:E/AndroidRuntime(7617):android.content.ActivityNotFoundException:未找到可处理意图的活动{act=EndgameActivity}
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Activity.startActivityForResult(Activity.java:3370)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Activity.startActivityForResult(Activity.java:3331)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Activity.startActivity(Activity.java:3566)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.app.Activity.startActivity(Activity.java:3534)
09-09 18:32:14.688:E/AndroidRuntime(7617):在com.abc.cyk.QuestionActivity.onClick(QuestionActivity.java:143)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.view.view.performClick(view.java:4204)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.view.view$PerformClick.run(view.java:17355)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.os.Handler.handleCallback(Handler.java:725)上
09-09 18:32:14.688:E/AndroidRuntime(7617):位于android.os.Handler.dispatchMessage(Handler.java:92)
09-09 18:32:14.688:E/AndroidRuntime(7617):在android.os.Looper.loop(Looper.java:137)上
09-09 18:32:14.688:E/AndroidRuntime(7617):位于android.app.ActivityThread.main(ActivityThread.java:5041)
09-09 18:32:14.688:E/AndroidRuntime(7617):位于java.lang.reflect.Method.Invokenactive(本机方法)
09-09 18:32:14.688:E/AndroidRuntime(7617):位于java.lang.reflect.Method.invoke(Method.java:511)
09-09 18:32:14.688:E/AndroidRuntime(7617):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-09 18:32:14.688:E/AndroidRuntime(7617):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-09 18:32:14.688:E/AndroidRuntime(7617):在dalvik.system.NativeStart.main(本机方法)
09-09 18:32:18.258:I/进程(7617):发送信号。PID:7617信号:9
09-09 18:32:18.758:E/Trace(7693):打开跟踪文件时出错:没有这样的文件或目录(2)
2009-09 18:32:18.908:D/dalvikvm(7693):释放58K的所有物质的GC_,8%的自由2413K/2616K,暂停26ms,总计27ms
09-09 18:32:18.918:I/dalvikvm堆(7693):为2160016字节分配将堆(frag案例)增长到4.553MB
2009-09 18:32:19.038:D/dalvikvm(7693):释放1K的所有数据的GC_,5%的自由数据4521K/4728K,暂停113ms,总计113ms

09-09 18:32:19.088:D/dalvikvm(7693):GC_CONCURRENT freedAddyour EndGame Activity在清单文件中。Logcat清楚地说

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=EndgameActivity }

只需将EndgameActivity添加到清单文件中的新活动标记内。

问题不在于找不到您的
EndgameActivity
。例外情况:

Check your manifest file you register activity
android.content.ActivityNotFoundException: No Activity found to handle Intent {     act=EndgameActivity }
ActivityNotFoundException: No Activity found to handle Intent { act=EndgameActivity }
告诉您,
EndgameActivity
以某种方式被视为动作。这很奇怪,因为您既没有使用构造函数意图(字符串):

也不使用Intent#setAction(字符串)

尝试使用完全限定的类名:

Intent i = new Intent(com.abc.cyk.QuestionActivity.this,
                                            com.abc.cyk.EndgameActivity.class);
你可以尝试的另一件事是:

Intent i = new Intent();
i.setClass(QuestionActivity.this, com.abc.cyk.EndgameActivity.class);
startActivity(i);
finish();
虽然它与当前版本无关,但我注意到在EndgameActivity#onCreate(Bundle)中,您使用了:

setContentView(findViewById(R.layout.endgame));
这应改为:

setContentView(R.layout.endgame);

我正在检查您的代码,请从代码中删除
findViewById

setContentView(findViewById(R.layout.endgame));

如果您在清单文件中声明了活动,请检查清单文件。您可能缺少注册或声明清单文件中的活动。。我已经在menifest文件中添加了该项。@raghundandan任何其他解决方案?@JohnR单击方法时您在哪里?
setContentView(R.layout.endgame);
setContentView(findViewById(R.layout.endgame));