我希望在按下“createAppointment”按钮时启动一个新活动,但到目前为止,当我单击该按钮时,应用程序崩溃了。
按钮的创建:
<Button
android:id="@+id/crtApp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appointment"
android:layout_gravity="center"/>
创建应用程序.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:id="@+id/createAppointment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="36sp"
android:text="Create Appointment"
android:textSize="34sp" />
<TextView
android:id="@+id/titleOfAppointment"
android:layout_width="318dp"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="24sp" />
<EditText
android:id="@+id/titleappointment"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginBottom="15sp"
android:layout_marginLeft="10dp"
android:ems="10" />
<TextView
android:id="@+id/timeappointment"
android:layout_width="318dp"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="24sp" />
<EditText
android:id="@+id/timeappointment"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginBottom="15sp"
android:layout_marginLeft="10dp"
android:ems="10" />
<TextView
android:id="@+id/detailsappointment"
android:layout_width="318dp"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="24sp" />
<EditText
android:id="@+id/detailsappointment"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:layout_marginBottom="65dp"
android:layout_marginLeft="10dp"
android:layout_weight="0.07"
/>
<Button
android:id="@+id/save_button"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_weight="0.01"
android:text="Save"/>
</LinearLayout>
创建约会.java
package com.examples;
import android.app.Activity;
import android.os.Bundle;
public class CreateAppointment extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.createapp);
}
}
按钮开始新活动的代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_calendar_view);
Button createAppointment = (Button)findViewById(R.id.crtApp);
createAppointment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.CREATEAPP"));
}
});
}
日志猫
04-25 15:17:13.719: W/dalvikvm(460): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-25 15:17:13.779: E/AndroidRuntime(460): FATAL EXCEPTION: main
04-25 15:17:13.779: E/AndroidRuntime(460): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CREATEAPP }
04-25 15:17:13.779: E/AndroidRuntime(460): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.app.Activity.startActivityForResult(Activity.java:2817)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.app.Activity.startActivity(Activity.java:2923)
04-25 15:17:13.779: E/AndroidRuntime(460): at com.examples.SimpleCalendarViewActivity$1.onClick(SimpleCalendarViewActivity.java:60)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.view.View.performClick(View.java:2408)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.view.View$PerformClick.run(View.java:8816)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.os.Handler.handleCallback(Handler.java:587)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.os.Looper.loop(Looper.java:123)
04-25 15:17:13.779: E/AndroidRuntime(460): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 15:17:13.779: E/AndroidRuntime(460): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 15:17:13.779: E/AndroidRuntime(460): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 15:17:13.779: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 15:17:13.779: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 15:17:13.779: E/AndroidRuntime(460): at dalvik.system.NativeStart.main(Native Method)