香港专业教育学院有一个问题。我想开一个按钮的活动,但它崩溃所有的时间。 所以,我创建了2类和一个按钮。但它总是死机。
Ive got a problem. I want to open an Activity with a Button but it crashes all the time. So I created 2 Classes and A Button. But it keeps crashing.
类是activity_home类()和第二个是schedule_act()类。activity_home类:
package my.action.bat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class activity_home extends Activity {
private Button ScheduleBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ScheduleBtn = (Button) findViewById(R.id.home_btn_schedule);
ScheduleBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent("my.action.bat.schedule_act");
startActivity(myIntent);
}
});
}
}
schedule_act类:
package my.action.bat;
import android.app.Activity;
import android.os.Bundle;
public class schedule_act extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.schedule_layout);
}
}
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.action.bat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".activity_home" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".schedule_act" >
<intent-filter >
<action android:name="my.action.bat.SCHEDULE_ACT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
非常感谢你。
Thank you very much.
意图是区分大小写的。更改
Intents are case sensitive. Change
"my.action.bat.schedule_act"
要
"my.action.bat.SCHEDULE_ACT"
此外,除非你真的需要使用意图,我将开始新的活动,像这样
Also, unless you really need to use an intent, I would start your activity like so
startActivity(new Intent(this, schedule_act.class));
如果这是一个上下文
子