下面是我正在编程的Android应用程序的代码。每当我点击按钮将我的应用程序带到新活动时,为什么我的应用程序崩溃?我的日食没有出现任何错误。
我该怎么做才能解决这个问题?谢谢,下面是代码:
package com.example.progressdialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
int numOfClicks;
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progress = new ProgressDialog(this);
}
//Added otherWays function
public void otherWays(View view){
((Button)view).setBackgroundColor(Color.BLUE);
setContentView(R.layout.main2);
startActivity(new Intent(MainActivity.this, Activity2.class ));
}
public void open(View view){
progress.setMessage("Processing!");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(false);
progress.show();
final int totalProgressTime = 100;
//use a AsyncTask instead
final Thread t = new Thread(){
@Override
public void run(){
int jumpTime = 0;
while(jumpTime < totalProgressTime){
try {
sleep(500);
jumpTime += 1;
progress.setProgress(jumpTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}}
答案 0 :(得分:0)
很难说没有任何日志或XML可供查看,但是......您是否将自己的活动添加到Android Manifest?
<activity
android:name="com.yourapp.android.Activity2"
android:label="@string/app_name" >
</activity>