我在切換活動時遇到了一些問題。我認爲這與我的viewflipper有關。每當我點擊「開始遊戲」按鈕切換到遊戲活動時,它會拋出錯誤「線程主要由於未捕獲的異常而退出」。任何人都可以幫我一把嗎?我知道肯定它不可能是開始遊戲活動和它的佈局,兩者都很簡單,不會失敗。就像我說過的,我認爲這與我的視圖翻轉器有關。更進一步,我想解釋更多。該活動以具有用戶名,密碼和登錄編輯文本/按鈕的視圖開始,然後當用戶和通行證被接受時,它將視圖翻轉到主菜單。從那裏,你按開始遊戲。無法更改活動
package com.login.test;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ViewFlipper;
public class Login extends Activity {
public EditText username, password;
public Button loginbutton, start, stats;
public ViewFlipper flip;
public String dbu, dbp;
final Handler handler = new Handler();
Timer t = new Timer();
public static final String KEEP_INFO = "remeberinfo";
public void startgame() {
Intent myIntent = new Intent(Login.this, Game.class);
startActivity(myIntent);
}
public void seescore() {
Intent myIntent2 = new Intent(Login.this, Score.class);
startActivity(myIntent2);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
username = (EditText) this.findViewById(R.id.username);
password = (EditText) this.findViewById(R.id.password);
loginbutton = (Button) this.findViewById(R.id.loginbutton);
start = (Button) this.findViewById(R.id.start);
stats = (Button) this.findViewById(R.id.stats);
flip = (ViewFlipper) this.findViewById(R.id.flip);
//when a view is displayed
flip.setInAnimation(this,android.R.anim.fade_in);
//when a view disappears
flip.setOutAnimation(this, android.R.anim.fade_out);
final Toast accessdenied = Toast.makeText(getApplicationContext(), "Incorrect username/password", 3);
final Toast accessgranted = Toast.makeText(getApplicationContext(), "Logging in", 3);
//calling for a stored data byte using sharedpreferences
SharedPreferences settings = getSharedPreferences(KEEP_INFO,0);
String keptusername = settings.getString("keptuser", "");
String keptpassword = settings.getString("keptpass", "");
username.setText(keptusername);
password.setText(keptpassword);
loginbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dbu = (username.getText()).toString();
dbp = (password.getText()).toString();
try{
}
finally{
if ((dbu.equals("crete"))&&(dbp.equals("monee"))){
username.setBackgroundResource(R.drawable.greenloginbutton);
password.setBackgroundResource(R.drawable.greenloginbutton);
loginbutton.setBackgroundResource(R.drawable.greenloginbutton);
accessgranted.show();
//setting and valuing a data byte using sharedpreferences
SharedPreferences info = getSharedPreferences(KEEP_INFO,0);
SharedPreferences.Editor editor = info.edit();
editor.putString("keptuser", dbu);
editor.putString("keptpass", dbp);
editor.commit();
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
flip.showNext();
}
});
}
}, 2000);
}
else {
t.schedule(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
username.setBackgroundResource(R.drawable.loginbutton);
password.setBackgroundResource(R.drawable.loginbutton);
loginbutton.setBackgroundResource(R.drawable.loginbutton);
}
});
}
}, 3000);
accessdenied.show();
username.setBackgroundResource(R.drawable.redloginbutton);
password.setBackgroundResource(R.drawable.redloginbutton);
loginbutton.setBackgroundResource(R.drawable.redloginbutton);
}
}
}
});
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startgame();
}
});
stats.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
seescore();
}
});
}
}
LOG CAT
01-28 12:03:56.125: D/dalvikvm(322): GC freed 594 objects/48504 bytes in 172ms
01-28 12:03:57.065: D/dalvikvm(322): GC freed 49 objects/1904 bytes in 131ms
01-28 12:03:57.838: D/ViewFlipper(322): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
01-28 12:04:09.176: D/AndroidRuntime(322): Shutting down VM
01-28 12:04:09.185: W/dalvikvm(322): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-28 12:04:09.195: E/AndroidRuntime(322): Uncaught handler: thread main exiting due to uncaught exception
01-28 12:04:09.267: E/AndroidRuntime(322): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.beeseries.contextclues/com.beeseries.contextclues.Game}; have you declared this activity in your AndroidManifest.xml?
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.Activity.startActivityForResult(Activity.java:2749)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.Activity.startActivity(Activity.java:2855)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.beeseries.contextclues.Login.startgame(Login.java:29)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.beeseries.contextclues.Login$2.onClick(Login.java:136)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.View.performClick(View.java:2364)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.View.onTouchEvent(View.java:4179)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.widget.TextView.onTouchEvent(TextView.java:6540)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.View.dispatchTouchEvent(View.java:3709)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.os.Looper.loop(Looper.java:123)
01-28 12:04:09.267: E/AndroidRuntime(322): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-28 12:04:09.267: E/AndroidRuntime(322): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 12:04:09.267: E/AndroidRuntime(322): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-28 12:04:09.267: E/AndroidRuntime(322): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-28 12:04:09.267: E/AndroidRuntime(322): at dalvik.system.NativeStart.main(Native Method)
01-28 12:04:09.315: I/dalvikvm(322): threadid=7: reacting to signal 3
01-28 12:04:09.435: I/dalvikvm(322): Wrote stack trace to '/data/anr/traces.txt'
01-28 12:04:12.485: I/Process(322): Sending signal. PID: 322 SIG: 9
請張貼滿logcat的,所以任何人都可以看到確切的問題。 – jeet 2012-01-28 04:58:25