我创建了一个应用程序,用于在点击提交按钮时将页面从第一个活动导航到第二个活动。但是当我运行我的项目时,我得到了#34;不幸的是应用程序停止了#34;。我已经发布了我的代码..请帮助我。
// main_activity ( 1st activity)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#ffff0000">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="23dp"
android:text="USER NAME"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="REGISTRATION FORM"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignRight="@+id/editText1"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView3"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/editText4"
android:layout_marginTop="34dp"
android:text="SUBMIT" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="textEmailAddress" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/textView2"
android:text="CANCEL" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="PASSWORD"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/editText2"
android:text="E-MAIL ID"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView5"
android:ems="10"
android:inputType="textPostalAddress" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/editText3"
android:text="ADDRESS"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
注册表活动(第二活动)
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff0000" >
<Button
android:id="@+id/button1"
android:layout_width="268dp"
android:layout_height="wrap_content"
android:layout_x="16dp"
android:layout_y="238dp"
android:text="PLACE ORDER"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="141dp"
android:text="YOU HAVE SUCCESSFULLY LOGGED IN"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:context=".RegistrationFormActivity" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="90dp"
android:layout_y="66dp"
android:text="WELCOME"
android:textAppearance="?android:attr/textAppearanceLarge" />
</AbsoluteLayout>
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pizza"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.pizza.MainActivity"
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=".RegistrationFormAcitvity"></activity>
</application>
</manifest>
main_activity java
package com.example.pizza;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addButtonOnClickEventListener();
}
private void addButtonOnClickEventListener()
{
// TODO Auto-generated method stub
Button button = (Button)findViewById(R.id.button1);
final Context context = MainActivity.this;
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent (context,RegistrationFormActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
注册表单java代码
package com.example.pizza;
import android.app.Activity;
import android.os.Bundle;
public class RegistrationFormActivity extends Activity
{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registrationform);
addButtonOnClickEventListener();
}
private void addButtonOnClickEventListener()
{
// TODO Auto-generated method stub
}
}
// logcat
02-11 02:46:20.049:D / gralloc_goldfish(1081):未检测到GPU仿真的仿真器。 02-11 02:46:22.899:D / AndroidRuntime(1081):关闭VM 02-11 02:46:22.909:W / dalvikvm(1081):threadid = 1:线程退出未捕获的异常(组= 0xb4a53b90) 02-11 02:46:22.909:E / AndroidRuntime(1081):致命异常:主要 02-11 02:46:22.909:E / AndroidRuntime(1081):进程:com.example.pizza,PID:1081 02-11 02:46:22.909:E / AndroidRuntime(1081):android.content.ActivityNotFoundException:无法找到显式活动类{com.example.pizza/com.example.pizza.RegistrationFormActivity};你有没有在AndroidManifest.xml中声明这个活动? 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Activity.startActivityForResult(Activity.java:3423) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Activity.startActivityForResult(Activity.java:3384) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Activity.startActivity(Activity.java:3626) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.Activity.startActivity(Activity.java:3594) 02-11 02:46:22.909:E / AndroidRuntime(1081):at com.example.pizza.MainActivity $ 1.onClick(MainActivity.java:36) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.view.View.performClick(View.java:4424) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.view.View $ PerformClick.run(View.java:18383) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.os.Handler.handleCallback(Handler.java:733) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.os.Handler.dispatchMessage(Handler.java:95) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.os.Looper.loop(Looper.java:137) 02-11 02:46:22.909:E / AndroidRuntime(1081):在android.app.ActivityThread.main(ActivityThread.java:4998) 02-11 02:46:22.909:E / AndroidRuntime(1081):at java.lang.reflect.Method.invokeNative(Native Method) 02-11 02:46:22.909:E / AndroidRuntime(1081):at java.lang.reflect.Method.invoke(Method.java:515) 02-11 02:46:22.909:E / AndroidRuntime(1081):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777) 02-11 02:46:22.909:E / AndroidRuntime(1081):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 02-11 02:46:22.909:E / AndroidRuntime(1081):at dalvik.system.NativeStart.main(Native Method) 02-11 02:46:32.989:I / Process(1081):发送信号。 PID:1081 SIG:9 02-11 02:46:37.069:D / gralloc_goldfish(1107):未检测到GPU仿真的仿真器。 02-11 02:46:45.309:D / AndroidRuntime(1107):关闭VM 02-11 02:46:45.309:W / dalvikvm(1107):threadid = 1:线程退出未捕获异常(组= 0xb4a53b90) 02-11 02:46:45.359:E / AndroidRuntime(1107):致命异常:主要 02-11 02:46:45.359:E / AndroidRuntime(1107):处理:com.example.pizza,PID:1107 02-11 02:46:45.359:E / AndroidRuntime(1107):android.content.ActivityNotFoundException:无法找到显式活动类{com.example.pizza/com.example.pizza.RegistrationFormActivity};你有没有在AndroidManifest.xml中声明这个活动? 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Activity.startActivityForResult(Activity.java:3423) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Activity.startActivityForResult(Activity.java:3384) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Activity.startActivity(Activity.java:3626) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.Activity.startActivity(Activity.java:3594) 02-11 02:46:45.359:E / AndroidRuntime(1107):at com.example.pizza.MainActivity $ 1.onClick(MainActivity.java:36) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.view.View.performClick(View.java:4424) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.view.View $ PerformClick.run(View.java:18383) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.os.Handler.handleCallback(Handler.java:733) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.os.Handler.dispatchMessage(Handler.java:95) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.os.Looper.loop(Looper.java:137) 02-11 02:46:45.359:E / AndroidRuntime(1107):在android.app.ActivityThread.main(ActivityThread.java:4998) 02-11 02:46:45.359:E / AndroidRuntime(1107):at java.lang.reflect.Method.invokeNative(Native Method) 02-11 02:46:45.359:E / AndroidRuntime(1107):at java.lang.reflect.Method.invoke(Method.java:515) 02-11 02:46:45.359:E / AndroidRuntime(1107):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777) 02-11 02:46:45.359:E / AndroidRuntime(1107):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 02-11 02:46:45.359:E / AndroidRuntime(1107):at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
编辑AndroidManifest.xml
<activity android:name="com.example.pizza.RegistrationFormAcitvity"></activity>
或
<activity android:name="RegistrationFormAcitvity"></activity>
再试一次