Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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 我的项目总是执行强制关闭_Android - Fatal编程技术网

Android 我的项目总是执行强制关闭

Android 我的项目总是执行强制关闭,android,Android,这是代码 这是第一节主要问题被提出的课。。 包com.tutle import com.turtle.R; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.InputType; import android.view.Gravity; import android.vi

这是代码

这是第一节主要问题被提出的课。。 包com.tutle

import com.turtle.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class Question extends Activity{



    protected static final String Level1 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.question);





        Button chkButton = (Button) findViewById(R.id.bresult);
        final EditText input = (EditText) findViewById(R.id.etext);
        final TextView tvresult = (TextView) findViewById(R.id.tvresult2);



        chkButton.setOnClickListener(new View.OnClickListener() {

            @Override
            // TODO Auto-generated method stub
            public void onClick(View v) {
                String answer = "Marianas Trench";
                String answer2 = "marianas trench";
                String answer3 = "MARIANAS TRENCH";

                Bundle b = new Bundle();
                b.putString("ANSWER", answer);

                String check = input.getText().toString();
                if (check.contentEquals(answer)){

                      b.putString("ANSWER", answer);

                      Intent intObj = new Intent(Question.this, Level1.class);
                      intObj.putExtras(b);
                      startActivity(intObj);

                    }else if (check.contentEquals(answer2)){

                      b.putString("ANSWER", answer);

                      Intent intObj = new Intent(Question.this, Level1.class);
                      intObj.putExtras(b);

                      startActivity(intObj);

                    }else if (check.contentEquals(answer3)){

                      b.putString("ANSWER", answer);

                      Intent intObj = new Intent(Question.this, Level1.class);
                      intObj.putExtras(b);

                    startActivity(intObj);

                    }else{

                    }



    }
        });
    }
}
这是由图像按钮组成的第二个类,如果单击,它将进入问题页面

package com.turtle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Level1 extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
this.setContentView(R.layout.level1);   



ImageButton btl1 = (ImageButton) findViewById(R.id.l1);
btl1.setOnClickListener (new View.OnClickListener()
{
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent myIntent= new Intent("com.turtleexploration.QUESTION");
        startActivity(myIntent);

    }
});
ImageButton btl2 = (ImageButton) findViewById(R.id.l2);
btl2.setOnClickListener (new View.OnClickListener()
{
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent myIntent= new Intent("com.turtleexploration.QUESTION2");
        startActivity(myIntent);

    }
});
ImageButton btBacklvl1 = (ImageButton) findViewById(R.id.backlvl1);
btBacklvl1.setOnClickListener (new View.OnClickListener()
{
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent myIntent= new Intent("com.turtleexploration.NEWGAME");
        startActivity(myIntent);

    }
});



    }

    }

我假设您的第一个活动开始,然后当您单击按钮时,您得到了一个FC

您可能有其他问题,但已将Level1声明为字符串对象。 如果不使用它,请将其删除或重命名。在意图构造函数中,Level1.class应该引用第二个活动的类

  Intent intObj = new Intent(Question.this, Level1.class);

最后,请确保您在清单中声明了1级活动。

您需要更清楚地了解您的问题是什么,症状是什么,以及您试图实现什么。好的,我正在尝试完成一个问答游戏,如果玩家是正确的。。然后类中按钮的图像被更改。。到目前为止,我可以做到这一点,因为有很多错误。。。在过去的几周里,我尽了最大的努力,但我仍然是android或java的新手……出了什么问题?您的错误是什么?您的错误具体发生在哪里?请显示您的日志。问题已通过try and catch解决。。但是。。我的项目没有输出。。除了给出答案外。。如果第一堂课的答案是正确的,那么第二堂课的按钮上的图片一定会有变化。问题活动的第一个字段受保护的静态最终字符串Level1=null;好吧,我来修。。现在没事了。。但仍然没有按钮改变图像的结果。