我希望在按下“createAppointment”按钮时启动新活动,但到目前为止,当我单击按钮时,应用程序崩溃。
创建按钮:
<Button
android:id="@+id/crtApp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appointment"
android:layout_gravity="center"/>
createApp.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>
CreateAppointment.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"));
}
});
}
LOG CAT
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)
答案 0 :(得分:3)
如果我理解得很好,你想按下按钮开始活动。然后你应该有这样的事情:
createAppointment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(your_context, CreateAppointment.class);
startActivity(intent);
}
});
希望它有所帮助!
(为了更好地理解你的错误日志:))
答案 1 :(得分:0)
检查以确保活动位于AndroidManifest.xml文件中。
答案 2 :(得分:0)
startActivity(new Intent(getBaseContext(), CreateAppointment.class));
并且像kailoon所说,“检查以确保活动在AndroidManifest.xml文件中。”
答案 3 :(得分:0)
您是否在清单文件中声明了活动? 除了旅行>
Intent i = new Intent();
i.setClassName(pkgname, activity name);
startActivity(i);
答案 4 :(得分:0)
<Button />
需要android:onClick="your method name here"
属性
和Java代码看起来应该是这样的
public void methodName(View view)
{
Intent intent = new Intent(this, ClassName.class);
startActivity(intent)
}