开发者

If TabHost acces ListActivity -> Nullpointer Exception

开发者 https://www.devze.com 2023-04-04 17:40 出处:网络
I created an Activity with an invisible TabHost which get\'s the content from an ListActivity which is filled by my database.

I created an Activity with an invisible TabHost which get's the content from an ListActivity which is filled by my database. If I open up my Activity with the TabHost in it, i get a Force Close Error. The Problem probably is in my ListActivity.

Here is the Code of my Activity with the Tabhost:

package de.retowaelchli.filterit;


import de.retowaelchli.filterit.stats.CreatedADFilters;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;


public class ADeleteActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.autodelete_test);

        TabHost tabHost = getTabHost();       

        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("All AutodeleteFilters").setContent(new Intent(this, CreatedADFilters.class)));
        tabHost.setCurrentTab(0);


    }
    /** Verweise auf die anderen Seiten **/
    public void onClickADConfig(View view){
        final Intent i = new Intent(this, ADFilterConfigActivity.class);
        startActivity(i); }
}

Here's the Layout-File for it:

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

       <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">

        <RelativeLayout
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent">
           <FrameLayout
               android:id="@android:id/tabcontent"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_weight="1" />
               <TabWidget
                   android:id="@android:id/tabs"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_alignBottom = "@android:id/tabcontent" 
                   android:visibility="invisible"/>

                   <TableRow 
                       android:layout_height="wrap_content" 
                       android:id="@+id/ADFilterOverview" 
                       android:layout_width="match_parent" 
                       android:onClick="onClickADConfig" 
                       android:layout_alignParentBottom="true" 
                       android:layout_alignParentLeft="true">

                        <TextView 
                        android:layout_gravity="bottom|left" 
                        android:text="@string/newadfilter" 
                        style="@style/NormalFont"/>
                </TableRow>
       </RelativeLayout>
      </TabHost>  
  </FrameLayout>

Now here you see the Code of my ListActivity:

package de.retowaelchli.filterit.stats;


import de.retowaelchli.filterit.R;
import de.retowaelchli.filterit.database.ADFilterDBAdapter;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;


public class CreatedADFilters extends ListActivity {

    //Variablen deklaration
    private ADFilterDBAdapter mDbHelper;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        mDbHelper=new ADFilterDBAdapter(this);
        fillData();

    }
    private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = mDbHelper.getAllADFilter();
        startManagingCursor(c);

        String[] from = new String[] { mDbHelper.NAME };
        int[] to = new int[] { R.id.empty };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter adname =
            new SimpleCursorAdapter(this, R.layout.list_layout, c, from, to);
        setListAdapter(adname);
    }
}

And here's the layout-file for it:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/NormalFont"
    android:id="@+id/empty" >
</TextView>

So what am I doing wrong.. :(

Thank you in advance.

Best Regards

safari

Here's the LogCat.

09-13 14:20:11.652: INFO/ActivityManager(1721): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=de.retowaelchli.filterit/.StartseiteActivity } from pid 1721
09-13 14:20:11.672: VERBOSE/HtcAppUsage开发者_如何学PythonStats(1721): (launch app, package): (Filter It, de.retowaelchli.filterit)
09-13 14:20:11.672: DEBUG/StatusBarManagerService(1721): disable what =0, token = android.os.Binder@40841360, pkg = android, mBar = com.android.internal.statusbar.IStatusBar$Stub$Proxy@40b46bb8
09-13 14:20:11.672: INFO/ActivityManager(1721): Start proc de.retowaelchli.filterit for activity de.retowaelchli.filterit/.StartseiteActivity: pid=3992 uid=10150 gids={}
09-13 14:20:11.812: INFO/SuperPowerSvc(29815): [SuperPowerSvc] App launched: [de.retowaelchli.filterit]
09-13 14:20:12.002: DEBUG/dalvikvm(1721): GC_EXTERNAL_ALLOC freed 1394K, 34% free 10500K/15815K, external 10208K/12256K, paused 147ms
09-13 14:20:12.232: WARN/ResourceType(1721): Skipping entry 0x7f040007 in package table 0 because it is not complex!
09-13 14:20:12.232: WARN/ResourceType(1721): Skipping entry 0x7f040008 in package table 0 because it is not complex!
09-13 14:20:12.272: DEBUG/SurfaceFlinger(1721): layer=0xc46a48 is not in the purgatory list
09-13 14:20:12.292: DEBUG/dalvikvm(3992): GC_EXTERNAL_ALLOC freed 44K, 50% free 2695K/5379K, external 0K/0K, paused 25ms
09-13 14:20:12.442: WARN/InputManagerService(1721): [unbindCurrentClientLocked] Disable input method client.
09-13 14:20:12.442: WARN/InputManagerService(1721): [startInputLocked] Enable input method client.
09-13 14:20:12.512: INFO/ActivityManager(1721): Displayed de.retowaelchli.filterit/.StartseiteActivity: +837ms
09-13 14:20:13.472: INFO/ActivityManager(1721): Starting activity: Intent { cmp=de.retowaelchli.filterit/.ADeleteActivity } from pid 3992
09-13 14:20:13.502: INFO/SuperPowerSvc(29815): [SuperPowerSvc] App launched: [de.retowaelchli.filterit]
09-13 14:20:13.622: DEBUG/dalvikvm(3992): GC_EXTERNAL_ALLOC freed 36K, 49% free 2769K/5379K, external 5760K/7192K, paused 22ms
09-13 14:20:13.742: DEBUG/AndroidRuntime(3992): Shutting down VM
09-13 14:20:13.742: WARN/dalvikvm(3992): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992): FATAL EXCEPTION: main
09-13 14:20:13.742: ERROR/AndroidRuntime(3992): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.retowaelchli.filterit/de.retowaelchli.filterit.ADeleteActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{de.retowaelchli.filterit/de.retowaelchli.filterit.stats.CreatedADFilters}: java.lang.NullPointerException
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.os.Looper.loop(Looper.java:143)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.main(ActivityThread.java:4196)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at java.lang.reflect.Method.invokeNative(Native Method)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at java.lang.reflect.Method.invoke(Method.java:507)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at dalvik.system.NativeStart.main(Native Method)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{de.retowaelchli.filterit/de.retowaelchli.filterit.stats.CreatedADFilters}: java.lang.NullPointerException
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1651)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:656)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.widget.TabHost.setCurrentTab(TabHost.java:326)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.widget.TabHost.addTab(TabHost.java:216)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at de.retowaelchli.filterit.ADeleteActivity.onCreate(ADeleteActivity.java:22)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     ... 11 more
09-13 14:20:13.742: ERROR/AndroidRuntime(3992): Caused by: java.lang.NullPointerException
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at de.retowaelchli.filterit.database.ADFilterDBAdapter.getAllADFilter(ADFilterDBAdapter.java:108)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at de.retowaelchli.filterit.stats.CreatedADFilters.fillData(CreatedADFilters.java:26)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at de.retowaelchli.filterit.stats.CreatedADFilters.onCreate(CreatedADFilters.java:21)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
09-13 14:20:13.742: ERROR/AndroidRuntime(3992):     ... 20 more
09-13 14:20:13.752: WARN/ActivityManager(1721):   Force finishing activity de.retowaelchli.filterit/.ADeleteActivity
09-13 14:20:13.752: WARN/ActivityManager(1721):   Force finishing activity de.retowaelchli.filterit/.StartseiteActivity
09-13 14:20:14.262: WARN/ActivityManager(1721): Activity pause timeout for HistoryRecord{4058e8d8 de.retowaelchli.filterit/.ADeleteActivity}
09-13 14:20:14.352: WARN/ResourceType(1721): Skipping entry 0x7f040006 in package table 0 because it is not complex!
09-13 14:20:14.352: WARN/ResourceType(1721): Skipping entry 0x7f040005 in package table 0 because it is not complex!

THE POST is updated with new Logcat and overdone code, from your posting's!


You are not crated the object for the ADFilterDBAdapter

 public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mDbHelper=new ADFilterDBAdapter(this);
    fillData();

}

and on more this is as per your code you created only one tab.so set the current tab index to zero(index starts from zero)

tabHost.setCurrentTab(0);


Set tabHost.setCurrentTab(0); and not tabHost.setCurrentTab(1);

Thats the reason for "NullPointerException".


I found it out, it was a lil Database-Problem the table didnt exist. thx for you help :D

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号