我對android非常陌生,事實上只在昨天開始。我設法使用選項卡來獲得應用程序設置。它在2.2虛擬AVD(我認爲它被稱爲)工作正常。但我的HTC版本是2.0.1 我發佈了以下代碼片段以及調試信息。Android java應用程序在一個版本上工作,但不是下一個
logcat中顯示以下錯誤
08-02 09:56:05.946: WARN/dalvikvm(414): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-02 09:56:05.956: ERROR/AndroidRuntime(414): Uncaught handler: thread main exiting due to uncaught exception
08-02 09:56:06.196: ERROR/AndroidRuntime(414): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.hyperActiveSolutions/org.hyperActiveSolutions.Organizer}: java.lang.NullPointerException
08-02 09:56:06.196: ERROR/AndroidRuntime(414): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
08-02 09:56:06.196: ERROR/AndroidRuntime(414): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
還有更多的這一點,但我認爲這是相關的位,剩下的只是長的堆棧跟蹤。
我的Android清單文件看起來像這樣
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.hyperActiveSolutions"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" android:name="Organizer">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Home" ></activity>
<activity android:name="Account"></activity>
<activity android:name="Agenda" ></activity>
<activity android:name="Lists" ></activity>
</application>
<uses-sdk android:minSdkVersion="6" android:targetSdkVersion="6"></uses-sdk>
</manifest>
正如你所看到的最小的SDK和目標已設置爲我的手機的版本。這是我入門課的開始。在這段代碼結束的地方,其他3個選項卡的添加方式與Home完全相同。
public class Organizer extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
final TabHost tabHost = getTabHost(); // The activity TabHost
// Create an Intent to launch an Activity for the tab (to be reused)
// Initialize a TabSpec for each tab and add it to the TabHost
tabHost.addTab(tabHost.newTabSpec("home").setIndicator("Home",
getResources().getDrawable(R.drawable.home)).setContent(new Intent().setClass(this, Home.class)));
我所有的資源都存在,包括我用每個選項卡實例化的類。 我能想到的唯一的另一件事可能是相關的是我的佈局main.xml。 它是從一個教程中的android開發站點複製而來的。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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" />
</LinearLayout>
</TabHost>
正如我所說的,它工作正常的2.2版本,但死在2.0.1和屏幕上顯示的消息只是「意外主辦termintated」反正消息....一部分。
所以任何人都可以發現任何我會讓它與2.0.1 SDK不兼容的東西。
在此先感謝
完整的堆棧跟蹤
08-02 11:47:54.006: WARN/dalvikvm(2588): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-02 11:47:54.016: ERROR/AndroidRuntime(2588): Uncaught handler: thread main exiting due to uncaught exception
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.organizer/com.organizer.Organizer}: java.lang.NullPointerException
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.os.Looper.loop(Looper.java:123)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread.main(ActivityThread.java:4338)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at java.lang.reflect.Method.invoke(Method.java:521)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at dalvik.system.NativeStart.main(Native Method)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): Caused by: java.lang.NullPointerException
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.widget.TabWidget.onFocusChange(TabWidget.java:351)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.View.onFocusChanged(View.java:2622)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.View.handleFocusGainInternal(View.java:2445)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:403)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.View.requestFocus(View.java:3562)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.requestFocus(ViewGroup.java:975)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1020)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.requestFocus(ViewGroup.java:976)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1020)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.requestFocus(ViewGroup.java:979)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1020)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.requestFocus(ViewGroup.java:976)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1020)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.ViewGroup.requestFocus(ViewGroup.java:979)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.View.requestFocus(View.java:3513)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.view.View.requestFocus(View.java:3491)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.widget.TabHost.setCurrentTab(TabHost.java:334)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.widget.TabHost.addTab(TabHost.java:213)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at com.organizer.Organizer.onCreate(Organizer.java:25)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
08-02 11:47:54.256: ERROR/AndroidRuntime(2588): ... 11 more
08-02 11:47:54.476: INFO/Process(62): Sending signal. PID: 2588 SIG: 3
08-02 11:47:54.476: INFO/dalvikvm(2588): threadid=7: reacting to signal 3
08-02 11:47:54.476: ERROR/dalvikvm(2588): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
08-02 11:48:01.446: INFO/dalvikvm(2588): Debugger has detached; object registry had 306 entries
08-02 11:48:02.466: DEBUG/ddm-heap(2588): Got feature list request
世界上大約有0個設備運行Android 2.0.1。 http://developer.android.com/resources/dashboard/platform-versions.html – CommonsWare 2010-08-02 11:05:24
@CommonsWare 我必須是其中一個不幸的事情,當我在eclipse中插入我的HTC時說它的2.0.1 – zcourts 2010-08-02 12:21:47