2013-03-02 79 views
-1

这是代码力...我的项目总是执行关闭

这是一个主要的问题是给.. 包com.turtle第一类;

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); 

    } 
}); 



    } 

    } 
+2

你需要更清楚你的问题是什么,症状是什么以及你试图完成什么。 – tmwoods 2013-03-02 17:52:27

+0

好吧,我试图完成一个问答游戏,如果玩家是正确的..然后从一个类的按钮图像被改变..截至目前,我可以做到这一点,因为许多错误...我尝试过去几周我所有的最好的,但即时通讯仍然是Android或java中的新手... – 2013-03-02 18:08:06

+0

什么错了?你得到的错误是什么? – cyroxx 2013-03-02 18:16:05

回答

0

我认为YOUT第一次活动开始,然后你已经得到了一个FC,当你点击你的按钮。

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

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

最后确定您已在清单中声明了Level1活动。

+0

即时确认没有声明为字符串.. – 2013-03-02 18:29:22

+0

http://stackoverflow.com/questions/15174629/how-to-change-the-image-of-a-button/15175908#comment21377795_15175908 – 2013-03-02 18:29:53

+0

看着你帖子。问题活动的第一个字段 protected static final String Level1 = null; – HoodVinci 2013-03-02 18:39:43