我正面临一个按钮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):at java.lang.reflect.Method.invokeNative(Native Method) 03-22 00:50:27.125:E / AndroidRuntime(857):at java.lang.reflect.Method.invoke(Method.java:507) 03-22 00:50:27.125:E / AndroidRuntime(857):在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:
<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>
答案 0 :(得分:2)
根据堆栈跟踪,您的清单文件似乎不会声明活动。检查<activity>
是否有Activity3
标记。
答案 1 :(得分:0)
在活动A中替换: 此
// @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);
}
来自此代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Using TextView to Give a Home Page Screen
TextView tv=new TextView(this);
tv.setText("WELCOME TO Application Click on Next to Proceed");
}