我做了一個應用程序,它工作正常。但是當我點擊「取消」或「確定」按鈕時,我運行該程序,而不是鏈接到result.java,模擬器給我「應用程序已經意外停止,請再試一次」代碼JAVA - Android錯誤:應用程序意外停止,請再試一次
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.CursorJoiner.Result;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
public class lib_main extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onAddClick (View botton){
AutoCompleteTextView title = (AutoCompleteTextView)findViewById(R.id.Title);
AutoCompleteTextView author = (AutoCompleteTextView)findViewById(R.id.Author);
AutoCompleteTextView isbn = (AutoCompleteTextView)findViewById(R.id.ISBN);
Intent intent = new Intent();
intent.setClass(this,Result.class);
intent.putExtra("Title", title.getText().toString());
intent.putExtra("Author", author.getText().toString());
intent.putExtra("ISBN", isbn.getText().toString());
startActivity(intent);
}
public void onCancelClick(View botton){
Intent intent = new Intent();
intent.setComponent(new ComponentName(this,Result.class));
intent.putExtra("Cancel","Cancel");
startActivity(intent);
}
}
這是Result.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView resultText=(TextView)findViewById(R.id.resultText);
Bundle bundle =getIntent().getExtras();
if(bundle.getString("Cancel")!= null)
{resultText.setText("operation cancel");}
else
{ String book =bundle.getString ("Title");
String title =bundle.getString ("Author");
String isbn =bundle.getString ("ISBN");
resultText.setText(
getString (R.string.resultOk)+""+book+""+ title+""+isbn);
}
}
}
錯誤日誌寫入「運行時,沒有命令的輸出:'我開始-N com.Library.doc/com.Library.doc.lib_main-A android.intent.action .MAIN-c android.intent.category.LAUNCHER'in device emulator -5554「
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Library.doc"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".lib_main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Result"
android:label="@string/result">
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
任何人都可以幫我解決這個問題嗎?
什麼可以幫助我們調試問題是發生錯誤的LogCat。這可能是發現問題的最快途徑。 – wheaties 2010-12-19 03:36:56
請發佈您的Manifest文件,這可能是問題的根源。 – st0le 2010-12-19 06:57:30
我認爲你的'result.java'實際上被命名爲'Result.java',不是嗎? – 2010-12-19 09:12:15