首页 > 代码库 > java.lang.IllegalArgumentException: The observer is null.最终解决方案

java.lang.IllegalArgumentException: The observer is null.最终解决方案

java.lang.IllegalArgumentException: The observer is null.最终解决方案

在使用数据适配的时候的问题:

java.lang.IllegalArgumentException: The observer is null.
	at android.database.Observable.unregisterObserver(Observable.java:64)
	at android.widget.BaseAdapter.unregisterDataSetObserver(BaseAdapter.java:42)
	at android.widget.AbsListView.onDetachedFromWindow(AbsListView.java:2872)
	at android.view.View.dispatchDetachedFromWindow(View.java:11908)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2647)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2645)
	at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2685)
	at android.view.ViewRootImpl.doDie(ViewRootImpl.java:4044)
	at android.view.ViewRootImpl.die(ViewRootImpl.java:4027)
	at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:375)
	at android.view.WindowManagerImpl$CompatModeWrapper.removeViewImmediate(WindowManagerImpl.java:170)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3352)
	at android.app.ActivityThread.access$1200(ActivityThread.java:140)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4914)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
	at dalvik.system.NativeStart.main(Native Method)
导致的问题所在是BaseAdapter
解决方案:在extends BaseAdapter的时候添加如下代码即可:

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		if (observer != null) {
	        super.unregisterDataSetObserver(observer);
	    }
	}

希望能帮助你,加油!

这里也是我:我的eoe博客关于这个问题地址

java.lang.IllegalArgumentException: The observer is null.最终解决方案