所以我刚刚给自己买了一台 Android 设备,想尝试一下 Android 开发,为自己创建一个简单的任务管理器。这个想法是实现 android 周围常见的选项卡 UI,所以我偶然发现了这个:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
一切都好。从现在起我需要道歉,因为我将不具体,因为我不知道问题出在哪里。发生的事情非常简单。我运行我的应用程序,出现一个对话框,显示“com.app.appname 被迫关闭”。就是这样。我没有看到用户界面。
所以,事不宜迟,我已经实现了:
概述.java:
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(资源/布局)
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Manifest.xml:
<?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>
据我所知,我已经修改了原始示例以使用我自己的一些类。这些类只是实现教程网站上看到的 hello world 消息。
请问我做错了什么?我似乎无法从调试器中得到任何有意义的信息...它没有指向我的代码中的任何内容,无论是在模拟器上还是在我的设备上运行。
对于粘贴大量代码,我深表歉意。如果我知道问题出在哪里,我就会把它删掉,但我不……!
谢谢。
编辑:logcat 说:
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]
最佳答案
就像 Falmarri 所建议的那样,您可能会缺少 AndroidManifest.xml 中的 Activity 。 ViewGoals 和 ViewGoals 是“Activity ”,对吗?如果是这样,请像概述一样将它们添加到 list 中。
LogCat 是与 Eclipse 集成的 Android 日志实用程序。转到“调试” View ,您应该会在那里看到它。
关于java - 修改后的 Tabhost 示例在启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4294243/