我正面臨onclick按鈕的問題。我檢查了以前提出的問題,但無法弄清楚問題所在,究竟在哪裏。第一次,當我點擊'下一步'按鈕時,它成功移動到下一頁,但在第二頁中,輸入詳細信息後,點擊'繼續'按鈕時,應用程序崩潰。當點擊一個按鈕時,應用程序被強制關閉
活動1:
package com.application.P1;
//import com.application.P1.R;
//import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class P1Activity extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
setContentView(R.layout.main);
}
public void Welcome(View v){
// Toast.makeText(this, "Please enter your Nickname and proceed further", Toast.LENGTH_SHORT).show();
Intent myActivity = new Intent(this,Activity2.class);
startActivity(myActivity);
// EditText t
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
活性2:
package com.application.P1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Activity2 extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
public void Proceed4(View v){
// Toast.makeText(this, "Thanks for entering your nickname", Toast.LENGTH_SHORT).show();
Intent myActivity2 = new Intent(this,Activity3.class);
startActivity(myActivity2);
// EditText t
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Activity3:
package com.application.P1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
//import android.content.Intent;
//import android.widget.Button;
import android.widget.Toast;
public class Activity3 extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
// @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
所有三項活動都在同一個包。在第二項活動中,點擊按鈕後,當消息被烘烤時,烘烤的消息就會正常顯示。但是,當下一個活動被調用時,它不會到來。
XML Coding:
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:text="@string/Next"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="Welcome"/>
</LinearLayout>
login.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/mynickname" />
<EditText
android:id="@+id/mynickname3"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:text="@string/Proceed"
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="Proceed4"/>
</LinearLayout>
Check.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello3" />
</LinearLayout>
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.P1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/cherry"
android:label="@string/app_name" >
<activity
android:name=".P1Activity"
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=".Activity2">
</activity>
<activity android:name=".Activity3"></activity>
</application>
</manifest>
03-22 00:50:27.125:E/AndroidRuntime(857):在java.lang.reflect.Method.invokeNative(本機方法) 03-22 00:50:27.125:E/AndroidRuntime(857 ):在java.lang.reflect.Method.invoke(Method.java:507) 03-22 00:50:27.125:E/AndroidRuntime(857):at android.view.View $ 1.onClick(View.java: 2139) 03-22 00:50:27.125:E/AndroidRuntime(857):... 11更多 03-22 00:50:27.125:E/AndroidRuntime(857):引起:android.content.ActivityNotFoundException:無法找到明確的活動
class {com.application.P1/com.application.P1.Activity3}; have you declared this activity in your AndroidManifest.xml?
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 00:50:27.125: E/AndroidRuntime(857): at android.app.Activity.startActivity(Activity.java:2933)
03-22 00:50:27.125: E/AndroidRuntime(857): at com.application.P1.Activity2.Proceed4(Activity2.java:31)
03-22 00:50:27.125: E/AndroidRuntime(857): ... 14 more
03-22 00:50:29.867: I/Process(857): Sending signal. PID: 857 SIG: 9
Values.xml:
從這個代碼 此// @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
setContentView(R.layout.main);
}
:在活動A
<string name="hello">Welcome to Expresso Application</string>
<string name="Next">Next</string>
<string name="app_name">Expresso2</string>
<string name="Proceed">Proceed</string>
<string name="Nickname">Nickname</string>
<string name="mynickname">myNickname</string>
<string name="hello3">Tensions</string>
請從logcat發佈和堆棧跟蹤異常。 (如果有幾個與「由......引起......」鏈接在一起,請發佈最後一個堆棧跟蹤。) – 2012-03-21 20:12:10
謝謝!這有助於......我附上最後一個堆棧跟蹤... – Mannii88 2012-03-21 20:13:07
嗨@TedHopp,期待您的回答...在問題中是否添加了最後一組堆棧跟蹤,對問題發出了任何提示? – Mannii88 2012-03-21 20:32:00