修改的TABHOST示例在启动上崩溃
-
28-09-2019 - |
题
因此,我刚刚拥有一个Android设备,并想开始一些Android开发,以创建一个简单的任务管理器。这个想法是实现Android周围看到的Tab UI,因此我偶然发现了这一点: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
都好。从这一点开始,我需要道歉,因为我将变得不合时宜,因为我不知道问题所在。发生的事情很简单。我运行了我的应用程序,我收到一个对话框,上面写着“ com.app.appname被迫关闭”。就是这样。我看不到UI。
因此,事不宜迟,我已经实施了:
overview.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(res/布局)
<?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>
subest.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中的活动。 ViewGoals和ViewGoals活动对吗?如果是这样,请像您概述一样将它们添加到清单中。
LogCat是与Eclipse集成的Android Log Util。转到调试视图,您应该在那里看到它。
其他提示
我修好了它。不知何故
android:id="@android:id/tabhost"
从我的塔博托主那里缺少。显然,这对于使事情正常工作至关重要!上面的答案是为我提供了一些有用的指针(LogCat),使我得以推论。
不隶属于 StackOverflow