gpt4 book ai didi

Android tabHost NullPointer

转载 作者:行者123 更新时间:2023-11-29 22:15:56 25 4
gpt4 key购买 nike

我是 android 编程的新手,但不是 Java。

我在以下位置收到有关 NPE 的错误消息:

12-09 10:29:58.247: D/dalvikvm(471): GC freed 711 objects / 54912 bytes in 163ms
12-09 10:29:58.337: D/dalvikvm(471): GC freed 45 objects / 1720 bytes in 37ms
12-09 10:29:58.457: D/AndroidRuntime(471): Shutting down VM
12-09 10:29:58.457: W/dalvikvm(471): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-09 10:29:58.457: E/AndroidRuntime(471): Uncaught handler: thread main exiting due to uncaught exception
12-09 10:29:58.457: E/AndroidRuntime(471): java.lang.NullPointerException
12-09 10:29:58.457: E/AndroidRuntime(471): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.os.Handler.dispatchMessage(Handler.java:99)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.os.Looper.loop(Looper.java:123)
12-09 10:29:58.457: E/AndroidRuntime(471): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-09 10:29:58.457: E/AndroidRuntime(471): at java.lang.reflect.Method.invokeNative(Native Method)
12-09 10:29:58.457: E/AndroidRuntime(471): at java.lang.reflect.Method.invoke(Method.java:521)
12-09 10:29:58.457: E/AndroidRuntime(471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-09 10:29:58.457: E/AndroidRuntime(471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-09 10:29:58.457: E/AndroidRuntime(471): at dalvik.system.NativeStart.main(Native Method)
12-09 10:29:58.467: I/dalvikvm(471): threadid=7: reacting to signal 3
12-09 10:29:58.467: E/dalvikvm(471): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

这让我发疯。我在网上搜索了一个解决方案,虽然我多次看到错误被引用,但他们要么没有发布解决方案,要么这些解决方案对我不起作用。

这是我的文件。我很感激你能给我的任何帮助。

WorkbenchTicketDetailsActivity.java

package com.android.fm.workbench;
import com.android.fm.workbench.R;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class WorkbenchTicketDetailsActivity extends WorkbenchActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticketdetails);
TabHost host = (TabHost)findViewById(R.id.tabhost);
host.setup();
TabSpec ticketdetailTab = host.newTabSpec("ticketdetails");
ticketdetailTab.setIndicator(getResources().getString(R.string.tablabel_ticketdetails),getResources().getDrawable(android.R.drawable.ic_menu_manage));
ticketdetailTab.setContent(R.id.TableLayout_TicketDetails);

host.setCurrentTabByTag("ticketdetails");


}
}

ticketdetails.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fm_background"
android:orientation="vertical" >
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/LinearLayout1"
android:orientation="vertical"
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">
<ScrollView
android:id="@+id/ScrollViewTicketDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<TableLayout
android:id="@+id/TableLayout_TicketDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test"
/>
</TableRow>
</TableLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.fm.workbench"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".WorkbenchActivity" >
</activity>
<activity android:name="WorkbenchTicketDetailsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>
<activity android:name="WorkbenchLoginActivity"></activity>
<activity android:name="WorkbenchSplashActivity">
</activity>
</application>

</manifest>

如果有一个我只是没有看到的简单解决方案,我深表歉意。很长一段时间以来,我一直在用头撞 table ,而且我知道这里有很多 super 明星,他们可以快速发现问题。

我尝试在 TabView 上从 Android 站点添加以下代码,并将现有的 ticketdetail.xml 代码替换为:

<?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: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>

仍然给我一个空指针异常!!!

最佳答案

为什么不将 tabspec 添加到主机中?

host.addTab(spec);

关于Android tabHost NullPointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8449007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com