我是安卓的自学者。
现在我在一个android应用程序中有五个页面。第一页包含两个按钮(button1,button2)。如果我触发button1它应该转到包含一个按钮的第二页,如果我最终触发这个按钮它应该只需显示一个位于第三页的选项卡主机。同样,如果我从第一页触发 button2,它应该像 button1 所做的那样转到第四页和第五页。
在运行期间,当我单击第四页中的按钮时,它显示错误消息为
对不起!应用程序 Tabhost_demo 已意外停止。请重试!
(注意:其他页面活动运行良好,而不是四个和五个)。
参考java类源码
public class First_index extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.button_parent);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Index_parent.class);
startActivityForResult(myIntent, 0);
}
});
这是用来切换页面的吧?
这个来源是为TABHOSTING
public class Parent_concpt extends TabActivity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main3);
TabHost tabHost = getTabHost();
// Tab for Attendance
TabSpec pho = tabHost.newTabSpec("Attendance");
// setting Title and Icon for the Tab
pho.setIndicator("Attendance",getResources().getDrawable(R.drawable.icon_att_parent));
Intent phoIntent = new Intent(this, Att_parents.class);
pho.setContent(phoIntent);
// Tab for Marks
TabSpec mrk = tabHost.newTabSpec("Achievement");
mrk.setIndicator("Achievement", getResources().getDrawable(R.drawable.icon_achieve_parents));
Intent mrkIntent = new Intent(this, Achieve_parents.class);
mrk.setContent(mrkIntent);
// Tab for Fee
TabSpec fees = tabHost.newTabSpec("Fee details");
fees.setIndicator("Fee details",getResources().getDrawable(R.drawable.icon_fee_details));
Intent feesIntent = new Intent(this, Feedet_parents.class);
fees.setContent(feesIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(pho);
tabHost.addTab(mrk);
tabHost.addTab(fees);}}
我的模棱两可是,我想问题只出在 Manifest.xml 文件上。是否有任何权限可以提及每个活动?
参考 Manifest.xml 源码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.demo.student"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name=".First_index"
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=".Index_parent"></activity>
<activity android:name=".Index_parent"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN1" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Parent_concpt"></activity>
<activity android:name=".Parent_concept"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN3" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Att_parents -->
<activity android:name=".Att_parents" />
<!-- Achieve_parents -->
<activity android:name=".Achieve_parents" />
<!-- Feedet_parents -->
<activity android:name=".Feedet_parents" />
<activity android:name=".Index_principal"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN2" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><activity android:name=".Princy_concept"></activity>
<activity android:name=".Princy_concept"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN7" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Att_principal Activity -->
<activity android:name=".Att_principal" />
<!-- Perform_principal Activity -->
<activity android:name=".Perform_principal" />
<!-- Coll_principal Activity -->
<activity android:name=".Coll_principal" />
<!-- Xpense_principal Activity -->
<activity android:name=".Xpense_principal" />
</application>
</manifest>
注意:我已经完美地完美地提到了每个类和布局的文件名。
请在此处参考我的 logcat LOGCAT
05-21 12:13:16.013: W/KeyCharacterMap(274): No keyboard for id 0
05-21 12:13:16.013: W/KeyCharacterMap(274): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
05-21 12:13:19.843: D/AndroidRuntime(274): Shutting down VM
05-21 12:13:19.843: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-21 12:13:19.853: E/AndroidRuntime(274): FATAL EXCEPTION: main
05-21 12:13:19.853: E/AndroidRuntime(274): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.demo.student/com.android.demo.student.Princy_concept}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.os.Looper.loop(Looper.java:123)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-21 12:13:19.853: E/AndroidRuntime(274): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 12:13:19.853: E/AndroidRuntime(274): at java.lang.reflect.Method.invoke(Method.java:521)
05-21 12:13:19.853: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-21 12:13:19.853: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-21 12:13:19.853: E/AndroidRuntime(274): at dalvik.system.NativeStart.main(Native Method)
05-21 12:13:19.853: E/AndroidRuntime(274): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.TabActivity.onContentChanged(TabActivity.java:105)
05-21 12:13:19.853: E/AndroidRuntime(274): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.Activity.setContentView(Activity.java:1647)
05-21 12:13:19.853: E/AndroidRuntime(274): at com.android.demo.student.Princy_concept.onCreate(Princy_concept.java:16)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-21 12:13:19.853: E/AndroidRuntime(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-21 12:13:19.853: E/AndroidRuntime(274): ... 11 more
谢谢你的帮助!