1. 程式人生 > >Weird error message in Android's MergeCursor

Weird error message in Android's MergeCursor

For an app I am working on I needed a MergeCursor to use search in a meaningful way. I needed to use two combine two cursors from different sources and I was going to merge them. The only major difference between the code for both cursors was the projection map I used to transform the db-specific column names to those the

SearchManager expects.

So when I merged both cursors I got the following error message:


java.lang.IllegalStateException: Observer [email protected] is already registered.

WTF? This message was not helpful. My code doesn't add any observers at all. So why then is an Observer already registered?

The reason of course was in my code. I used a MergeCursor that merges two CursorWrapper objects. Being the lazy guy that I am I simply copied the code for the first cursor and pasted it right below itself to finally merge both. And boy, was I bitten by the copy/paste-bug. For the copied code I renamed everything - but forgot to rename the cursor to be wrapped. And this was what caused this weird message to appear.

AbstractCursor inherits from Observable. So my cursor also was an Observable. And MergeCursor uses an anynomous DataSetOberserver implementation that it wants to register for each Cursor to merge. Since I did accidentally use the same cursor twice, also the same observer (the one within MergeCursor) was registered twice. Thus the exception.

I made a simple mistake in that I didn't update the variable name in one place - and hunted around for way too long. We all know that copy/paste is bad. But, alas, we sometimes forget to act accordingly. Let's hope I learned my lesson this time 🙂

Did you stumble upon anything comparable? Any stories you want to share? Let us know in the comments below.

相關推薦

Weird error message in Android's MergeCursor

For an app I am working on I needed a MergeCursor to use search in a meaningful way. I needed to use two combine two

IDE0006 Error running Xamarin Android project in Visual Studio

del str 耐心 get running 需要 一個 mod uget 這個報錯一般發生在剛創建了一個cross-platform時候發生; 解決方法: 在解決方案上右擊--管理解決方案的nuget程序包; 選擇更新標簽--勾選xamarin.form--然後點擊更新

Effects of Java’s Synthetic Accessor Methods in Android

Effects of Java’s Synthetic Accessor Methods in Android https://medium.com/thoughts-overflow/effects-of-javas-synthetic-accessor-methods-in-and

Error message: “'chromedriver' executable needs to be available in the path”

下載一個chromedriver(https://chromedriver.storage.googleapis.com/index.html?path=2.44/) 直接把chromedriver.exe放到你執行.py程式的下面(也就是工作目錄下) 或者直接這樣: browser = webd

“Nothing to push” error in Android studio with Git

在Android studio下使用git 參考:http://www.tuicool.com/articles/V7j6Zfq 1.準備安裝 git : sudo apt-get install git-core 參考:https://www.digitalocean.

How To Handle Network On Main Thread Error In Android

NetworkOnMainThreadException is a pretty popular exception among those new to android development. This exception is mainly thrown whenever an applicati

Beginner’s Guide to Dagger in Android

Beginner’s Guide to Dagger in AndroidWhat is Dagger? Newer developers tend to think it’s a library that simply enables the use of dependency injection — th

Use Android's ContentObserver in Your Code to Listen to Data Changes

When you are using a content provider as a client, chances are that you want to know whenever the data changes. That'

How to Correctly Use SQL's like in Android

Yesterday I stumbled about the correct usage of the LIKE-statement in conjunction with selectionArgs. My first attemp

Displaying Error Hints in Forms on Android

Displaying error messages in forms on Android is really simple. Most widgets have a setError(CharSequence text) metho

“/dev/kvm not found ”error on windows in android studio

I faced this issue and after some investigation, I concluded that the problem lies with the installer for HAXM and the way it is used.

SevenZip.SevenZipLibraryException: Can not load 7-zip library or internal COM error! Message: failed to load library.

exc dll library github ror cep mas 版本 .com SevenZip.SevenZipLibraryException: Can not load 7-zip library or internal COM error! Message:

mysql初始化錯誤【一】Can't find error-message file '/usr/local/mysql/errmsg.sys'

mysql初始化環境:CentOS 7.2 MySQL 5.7.18 從mysql官方網站下載rpm包到服務器本地,依次安裝下面的RPM包: mysql-community-common-5.7.18-1.el7.x86_64.rpm mysql-community-serve

The method Inflate() in android

androi eth height between _id sed dial font views Inflate() method can find out a layout defined by xml,as like the findViewById() me

ionic3打包出錯ionic cordova build android(系列一):could not find an installed version of gradle either in android studio

lan 問題 打包 fail .html ascii failed contains ref 1.運行ionic cordova build android 時報錯:could not find an installed version of gradle either i

Ubuntu 16.04升級4.7.0內核後導致Compiz奔潰,問題:compiz[4852]: segfault at 48 ip 00007f88cae087f0 sp 00007ffce354c268 error 4 in libscale.so

conf bsp alt get onf 桌面 支持 png style 由於硬件的驅動支持問題,升級4.7.0的內核主要是為了能使用Intel HD Graphics 630驅動,但是也出現了相關問題,比如Compiz的特效導致桌面上如果有多個相同程序啟動,然後再次點擊時

Common Words Used in Android

device ive rate ict ren item cau ble span retrieve to get something back scrap to discard or discontinue something because it is consid

What is “passive data structure” in Android/Java?

nag holding bstr say roi containe ive ces get From the Android developer web link: http://developer.android.com/reference/android/content

Xcode Error returned in reply: Connection invalid

一個 rep too mman log ror eply cnblogs command 當電腦上有Xcode兩個版本是使用其中的某一個的Simulator時出現了這樣的報錯 在Preference->Location->Command Line Too

安裝Android studio出現'tools.jar' seems to be not in Android Studio classpath......的解決方法

eas 一個 origin java_home ems view 使用 分享 title 安裝Android studio出現‘tools.jar‘ seems to be not in Android Studio classpath......的解決方法 原創 201