我的原型android应用程序(我应该提到它是我的第一个)崩溃,每当我通过eclipse运行它,一旦打开它。我搜索了这个网站和其他许多人,这个问题似乎很常见,但对我来说并不是这样。我已经检查了 AndroidManifest.xml 文件并且相当确定它是正确的,但无论如何我都将它附在此处。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyphr"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".NSBHSActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DayActivity"
android:label="@string/app_name">
</activity>
<activity android:name=".WeekActivity"
android:label="@string/app_name">
</activity>
</application>
以下是logcat消息,从程序开始到它死亡,据我所知。
08-09 18:23:57.342: INFO/dalvikvm(24229): Debugger has detached; object registry had 1 entries 08-09 18:23:57.358: ERROR/AndroidRuntime(24229): ERROR: thread attach failed 08-09 18:23:57.756: INFO/ActivityManager(1194): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.cyphr/.NSBHSActivity } 08-09 18:23:57.795: INFO/dalvikvm(24239): Debugger has detached; object registry had 1 entries 08-09 18:23:57.819: ERROR/AndroidRuntime(24239): ERROR: thread attach failed 08-09 18:23:57.897: INFO/ActivityManager(1194): Start proc com.cyphr for activity com.cyphr/.NSBHSActivity: pid=24246 uid=10103 gids={} 08-09 18:23:57.959: INFO/foo(1194): ********************** resuming: 1143348080 08-09 18:23:58.155: ERROR/dalvikvm(24246): Stack overflow on calling method: 08-09 18:23:58.155: ERROR/dalvikvm(24246): android.content.res.AssetManager.loadResourceValue() 08-09 18:23:58.155: ERROR/dalvikvm(24246): prototype : (ILandroid/util/TypedValue;Z)I 08-09 18:23:58.155: ERROR/dalvikvm(24246): shorty : IILZ 08-09 18:23:58.155: ERROR/dalvikvm(24246): registersSize : 4 08-09 18:23:58.155: ERROR/dalvikvm(24246): insSize : 4 08-09 18:23:58.178: ERROR/dalvikvm(24246): outsSize : 0 08-09 18:23:58.178: ERROR/dalvikvm(24246): method 0x4108cf64, rPC 0x4205308e, self->curFrame 0x4104c224 08-09 18:23:58.178: ERROR/dalvikvm(24246): rGLUE 0xbef439f8: 08-09 18:23:58.178: ERROR/dalvikvm(24246): rGLUE->pc 0x41fe8b68, rGLUE->fp 0x4104eeb8, rGLUE->method 0x4108d5b4: 08-09 18:23:58.178: ERROR/dalvikvm(24246): android.content.res.AssetManager.getResourceValue() 08-09 18:23:58.178: ERROR/dalvikvm(24246): prototype : (ILandroid/util/TypedValue;Z)Z 08-09 18:23:58.178: ERROR/dalvikvm(24246): shorty : ZILZ 08-09 18:23:58.178: ERROR/dalvikvm(24246): registersSize : 8 08-09 18:23:58.178: ERROR/dalvikvm(24246): insSize : 4 08-09 18:23:58.178: ERROR/dalvikvm(24246): outsSize : 4 08-09 18:23:58.178: INFO/dalvikvm(24246): Stack overflow, expanding (0x4104c200 to 0x4104c000) 08-09 18:23:58.178: INFO/dalvikvm(24246): Current stack size is 12288 08-09 18:23:58.178: INFO/dalvikvm(24246): "main" prio=5 tid=3 RUNNABLE 08-09 18:23:58.178: INFO/dalvikvm(24246): | group="main" sCount=0 dsCount=0 s=N obj=0x4001e368 self=0xbd90 08-09 18:23:58.178: INFO/dalvikvm(24246): | sysTid=24246 nice=0 sched=0/0 cgrp=unknown handle=-1343993120来自NSBHSActivity的
onCreate(),如要求:
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; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, DayActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("day").setIndicator("Day",
res.getDrawable(R.drawable.ic_tab_day))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, WeekActivity.class);
spec = tabHost.newTabSpec("week").setIndicator("Week",
res.getDrawable(R.drawable.ic_tab_day))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
评论是否需要额外信息。另外,正如我所说,这是我的第一个Android应用程序,但我有很好的Java经验。
答案 0 :(得分:1)
我认为android:theme="@android:style/Theme.NoTitleBar"
不是有效标签..将其删除并检查。
答案 1 :(得分:1)
您已将应用程序标记放在清单标记之外:使用如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyphr"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" >
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".NSBHSActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DayActivity"
android:label="@string/app_name">
</activity>
<activity android:name=".WeekActivity"
android:label="@string/app_name">
</activity>
</application>
</manifest>
答案 2 :(得分:0)
我终于发现它是因为图像文件名。他们需要ic_tab_day_grey.png
和ic_tab_day_white.png
状态列表才能接受它们。好极了!
谢谢大家的帮助!