Java 修改的Tabhost示例在启动时崩溃
所以我刚买了一台Android设备,想尝试一下Android的开发,为自己创建一个简单的任务管理器。这个想法是为了实现android上随处可见的tab UI,所以我偶然发现: 一切都好。从这一点开始,我需要道歉,因为我不知道问题出在哪里,所以我将不具体。发生的事情很简单。当我运行我的应用程序时,我会看到一个对话框,上面写着“com.app.appname被迫关闭”。就这样。我看不到用户界面 因此,我毫不犹豫地实现了: Overview.java:Java 修改的Tabhost示例在启动时崩溃,java,android,android-tabhost,Java,Android,Android Tabhost,所以我刚买了一台Android设备,想尝试一下Android的开发,为自己创建一个简单的任务管理器。这个想法是为了实现android上随处可见的tab UI,所以我偶然发现: 一切都好。从这一点开始,我需要道歉,因为我不知道问题出在哪里,所以我将不具体。发生的事情很简单。当我运行我的应用程序时,我会看到一个对话框,上面写着“com.app.appname被迫关闭”。就这样。我看不到用户界面 因此,我毫不犹豫地实现了: Overview.java: public class Overview ex
public class Overview extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, ViewTasks.class);
spec = tabHost.newTabSpec("tasks").setIndicator("Tasks",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ViewGoals.class);
spec = tabHost.newTabSpec("goals").setIndicator("Goals",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
main.xml(res/layout)
正如Falmari所说,您可能缺少AndroidManifest.xml中的活动。ViewGoals和ViewGoals是活动,对吗?如果是这样,请将它们添加到清单中,就像您所做的那样
LogCat是与Eclipse集成的Android日志util。转到“调试”视图,您应该会在那里看到它。我修复了它。不知怎的,这条线
android:id="@android:id/tabhost"
我的主播不见了。显然,这对于让事情顺利进行非常重要!上面的答案是因为给了我一些有用的指针(logcat),让我可以推断出这一点。您可能还没有在清单中列出您的活动。但是你得把你的航海日志贴出来让我们知道艾米的舱单在上面。我已经列出了我的活动,包括必要的意图过滤器,再加上一些我认为不会造成伤害的额外内容。什么是logcat?是的,它在那里。好的,我已经为ViewTasks和ViewGoals添加了活动定义。出现的错误似乎是android正在寻找一个不存在的类。。。但我从来没有,在任何地方,告诉过它去办那个班?基本上是对的。如果没有LogCat的建议,我将无法找到正在发生的错误消息。因此,为一个相当不具体的问题指出正确的方向而获得的分数。是的,我推断出来了,但根据他的建议。我只是觉得给他答案更好。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="the.correct.package.name"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="vxataskmaster">
<activity android:name="Overview" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="ViewGoals" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="ViewTasks" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
11-27 22:51:32.871: ERROR/AndroidRuntime(10662): java.lang.RuntimeException: Unable to instantiate application correct.root.package.taskmaster.ataskmaster: java.lang.ClassNotFoundException: correct.root.package.taskmaster.ataskmaster in loader dalvik.system.PathClassLoader[/data/app/correct.root.package.taskmaster-1.apk]
android:id="@android:id/tabhost"