2010-08-02 31 views
3

我对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

世界上大约有0个设备运行Android 2.0.1。 http://developer.android.com/resources/dashboard/platform-versions.html – CommonsWare 2010-08-02 11:05:24

+0

@CommonsWare 我必须是其中一个不幸的事情,当我在eclipse中插入我的HTC时说它的2.0.1 – zcourts 2010-08-02 12:21:47

回答

2

什么SDK版本您使用的构建项目?如果它高于6,你必须确保你没有使用已经在版本6之后添加的sdk的部分。我在问,因为它接缝像你从目标版本8(2.2)

如果这没有帮助,也许你可以发布可能给出其他线索的完整堆栈跟踪。

+0

我从2.2中退出,上面的堆栈跟踪是针对同一个项目的新版本,我刚刚创建了一个新的2.0.1版本的android项目,然后更新了清单和其他xml是相同的。正如你可以看到发生相同的错误 添加完整的堆栈跟踪。 我不知道我的手机是什么版本,当我开始按照来自android dev网站的教程,但是一旦我插入它来做一个测试eclipse说它是2。0.1所以我编辑了项目属性并更改为2.0.1 – zcourts 2010-08-02 12:27:40

+0

您是否检查过编译时使用的sdk版本? – Key 2010-08-02 16:16:56

+0

是的,除非有东西丢失。我已经检查过,项目属性和它肯定选择了正确的版本。 它似乎不适用于版本2.1更新1。我做了一个完全没有的项目,从头到尾跟着教程,它和它一样。继任何其他教程的应用程序工作正常在各种版本,它似乎只是可能导致问题 – zcourts 2010-08-02 18:22:33

1

您没有包含Home类的代码;你是不是意外地把Home的内容视图设置为R.layout.main?我得到了这个确切的错误,这就是问题所在 - 我将标签的内容视图设置为包含TabWidget本身的内容视图

+0

问题的选项卡,我重新从头开始的类,它最终运行良好,但我不会感到惊讶,如果这是什么问题是 – zcourts 2010-12-11 10:19:59

相关问题