不幸的是,应用程序已停止,但在单击“确定”时会继

时间:2015-03-26 14:49:18

标签: android

我有20个活动的申请。 当我在手机中运行应用程序时,它会从活动1到18轻轻地运行。但是在第18个活动中,当我单击OK in alert对话框时,我的应用程序已停止。但是当我单击OK时,应用程序继续并返回到活动17.并且在第18个活动中,当我从对话框中单击OK继续到第18个活动时。

但是当我将应用程序运行到我的模拟器时,它完全正常。

这是我在第17次活动中的代码

public class Luzon8Trivia extends Activity {
	private Button nextQ8;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.luzon8_trivia);
		
		Intent intent=getIntent();
		int myValue=intent.getIntExtra("parameter name", 0);
		final int answer=myValue + 10;
		nextQ8=(Button)findViewById(R.id.btnNextQuestion);
		nextQ8.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent=new Intent(Luzon8Trivia.this, Luzon09.class);
				intent.putExtra("parameter name", answer);
				startActivity(intent);
				overridePendingTransition(R.animator.transition_fade_in, R.animator.transition_fade_out);}
		});
	}
}

这是我在第18次活动中的代码

public class Luzon09 extends Activity {
	private int currentQuestion;
	private String [] answers;
	private Button answerButton;
	private TextView scoreTxt, showClue;
	private EditText answerText;
	int newCoin, myValue;
	int newScore, newScore2=0;
	private Button luz9he1, luz9he2, luz9he3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.luzon09);
		Intent intent=getIntent();
		int myValue=intent.getIntExtra("parameter name", 0);
		newCoin=myValue;
		scoreTxt=(TextView)findViewById(R.id.score);
		scoreTxt.setText("" + newCoin);
		
		showClue=(TextView)findViewById(R.id.txtviewClue);
		
		//accepts user input
		answerText=(EditText)findViewById(R.id.AnswerText);
		
		init2();
		
		luz9he1=(Button)findViewById(R.id.btnLuz1);
		luz9he1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				 if (newCoin>=10){
			           	AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this);
			            builder.setTitle("Need some Help?");
			            builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?");
			            builder.setIcon(android.R.drawable.ic_dialog_info);
			            builder.setPositiveButton("YES",  new DialogInterface.OnClickListener() {
			                 public void onClick(DialogInterface dialog, int which) {
			                	 newCoin-= 20;
			                	 scoreTxt.setText("" + newCoin);
			                	 luz9he1.setEnabled(false);
			     				showClue.setText("The province has been known as the Historical Capital of the Philippines");
			                 return;  }
			                            });// +
			            builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int which) {
							}
						});
			            AlertDialog alert = builder.create();
					    alert.show();	
					   }
			    	  else {Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show();
 }
			}
		});//end of help 1
		
		luz9he2=(Button)findViewById(R.id.btnLuz11);
		luz9he2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				 if (newCoin>=10){
				           	AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this);
				            builder.setTitle("Need some Help?");
				            builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?");
				            builder.setIcon(android.R.drawable.ic_dialog_info);
				            builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
				                 public void onClick(DialogInterface dialog, int which) {
				                	 newCoin-= 20;
				                	 scoreTxt.setText("" + newCoin);
				     				 luz9he2.setEnabled(false);
				     				showClue.setText("It is surrounded by Laguna province to the east, Metro Manila to the northeast, and Batangas province to the south.");
				                 return;  }
				                            }); //+
				            builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog, int which) {
								}
							});
				            AlertDialog alert = builder.create();
						    alert.show();	
						   }
				    	  else { Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show();
 }
					}
				});//end of help 2
		
		luz9he3=(Button)findViewById(R.id.btnLuz111);
		luz9he3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				 if (newCoin>=10){
				           	AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this);
				            builder.setTitle("Need some Help?");
				            builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?");
				            builder.setIcon(android.R.drawable.ic_dialog_info);
				            builder.setPositiveButton("YES",  new DialogInterface.OnClickListener() {
				                 public void onClick(DialogInterface dialog, int which) {
				                	 newCoin-= 20;
				                	 scoreTxt.setText("" + newCoin);
				     				luz9he3.setEnabled(false);
				     				showClue.setText("It is one of the most industrialized and one of the fastest growing provinces in the country.");
				                 return;  }
				                            }); //+
				            builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog, int which) {
								}
							});
				            AlertDialog alert = builder.create();
						    alert.show();	
						    }
				    	  else {Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show();
}
					}
				});//end of help 2

		
	}

	public void onBackPressed() {
		startActivity(new Intent(Luzon09.this, MainMenu.class));
		finish();
	    return;
	}
	public void init2()
	{
	//correct answer
	answers=new String[]{"Cavite"};
	
	//accepts user input
	answerText=(EditText)findViewById(R.id.AnswerText);
	
	//checks if the answer is correct
	answerButton=(Button)findViewById(R.id.AnswerButton);
	answerButton.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			checkAnswer();
		}
	});
	}
	
	public boolean isCorrect(String answer)
	{	return(answer.equalsIgnoreCase(answers[currentQuestion]));	}

	public void checkAnswer()
	{	String answer=answerText.getText().toString();	

		if(isCorrect(answer))
		{		
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("What are you a GENIUS?!");
            builder.setMessage("Nice one, Genius! You have P10!");
            builder.setIcon(android.R.drawable.btn_star);
            builder.setPositiveButton("View Trivia",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            	String userData=scoreTxt.getText().toString();
            	int userNumber=Integer.parseInt(userData);
            	Intent intent=new Intent(Luzon09.this, Luzon09Trivia.class);
            	intent.putExtra("parameter name", userNumber);
            	startActivity(intent);
            	overridePendingTransition(R.animator.transition_fade_in, R.animator.transition_fade_out);
            	;} });
            	AlertDialog alert = builder.create();
     		    alert.show(); // Show Alert Dialog
     			scoreTxt.setVisibility(View.GONE);
     			 
                 //disable all the buttons and textview
     			answerText.setEnabled(false);
     			answerButton.setClickable(false);		
     						}
     		else 
     		{
     			Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show();
     			}
     		
     	}
     	}

请原谅我的长码。

1 个答案:

答案 0 :(得分:0)

检查您的Menifest文件,无论您是否为activity18编写活动

<activity android:name="activity_name"></activity>

并且将Emulate App直接发送到手机,你必须写

android:installLocation="auto"

之后的menofest文件中的

android:versionCode="1"
android:versionName="1.0"

然后将手机连接到电脑并启用USB debuging。