SQLite异常无法将BLOB转换为字符串
在我的android项目中,我在从数据库检索数据时遇到一个问题。 在此我尝试从数据库获取字符串值(如 URL),但是当执行此代码时,我收到此错误 android.database.sqlite.SQLiteException:未知错误:无法将 BLOB 转换为字符串 只有 URL 列给我这个错误,而不是任何其他字符串列。
我没有明白我错在哪里。所以朋友请给我建议如何解决这个问题。这里我还打印了我的LogCat。
谢谢。
08-22 20:08:12.290: WARN/System.err(10844): android.database.sqlite.SQLiteException: unknown error: Unable to convert BLOB to string
08-22 20:08:12.300: WARN/System.err(10844): at android.database.CursorWindow.getString_native(Native Method)
08-22 20:08:12.300: WARN/System.err(10844): at android.database.CursorWindow.getString(CursorWindow.java:329)
08-22 20:08:12.300: WARN/System.err(10844): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.ProductsDetailsHomeTab.getProductDeatilsFromDB(ProductsDetailsHomeTab.java:337)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.ProductsDetailsHomeTab.setFlipperChild1(ProductsDetailsHomeTab.java:201)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.Widget.ViewFlipper_ProductDetails.onRightToLeftSwipe(ViewFlipper_ProductDetails.java:68)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.Widget.ViewFlipper_ProductDetails.onTouchEvent(ViewFlipper_ProductDetails.java:131)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.View.dispatchTouchEvent(View.java:3766)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
08-22 20:08:12.300: WARN/System.err(10844): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 20:08:12.300: WARN/System.err(10844): at android.os.Looper.loop(Looper.java:123)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 20:08:12.300: WARN/System.err(10844): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 20:08:12.300: WARN/System.err(10844): at java.lang.reflect.Method.invoke(Method.java:521)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-22 20:08:12.300: WARN/System.err(10844): at dalvik.system.NativeStart.main(Native Method)
In my android project I fetch one problem during retrieving data from data base.
In this I try to get String value from DB like URL but when this code execute then I get this error
android.database.sqlite.SQLiteException: unknown error: Unable to convert BLOB to string
And only URL colomn give me this error not any other string colomn.
I didn't get where I am wrong. So friend please give me suggestion how I can resolve this problem. Here I also print my LogCat.
Thank You.
08-22 20:08:12.290: WARN/System.err(10844): android.database.sqlite.SQLiteException: unknown error: Unable to convert BLOB to string
08-22 20:08:12.300: WARN/System.err(10844): at android.database.CursorWindow.getString_native(Native Method)
08-22 20:08:12.300: WARN/System.err(10844): at android.database.CursorWindow.getString(CursorWindow.java:329)
08-22 20:08:12.300: WARN/System.err(10844): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.ProductsDetailsHomeTab.getProductDeatilsFromDB(ProductsDetailsHomeTab.java:337)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.ProductsDetailsHomeTab.setFlipperChild1(ProductsDetailsHomeTab.java:201)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.Widget.ViewFlipper_ProductDetails.onRightToLeftSwipe(ViewFlipper_ProductDetails.java:68)
08-22 20:08:12.300: WARN/System.err(10844): at com.catLog.Widget.ViewFlipper_ProductDetails.onTouchEvent(ViewFlipper_ProductDetails.java:131)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.View.dispatchTouchEvent(View.java:3766)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1676)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1112)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1660)
08-22 20:08:12.300: WARN/System.err(10844): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
08-22 20:08:12.300: WARN/System.err(10844): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 20:08:12.300: WARN/System.err(10844): at android.os.Looper.loop(Looper.java:123)
08-22 20:08:12.300: WARN/System.err(10844): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 20:08:12.300: WARN/System.err(10844): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 20:08:12.300: WARN/System.err(10844): at java.lang.reflect.Method.invoke(Method.java:521)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-22 20:08:12.300: WARN/System.err(10844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-22 20:08:12.300: WARN/System.err(10844): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 getBlob() 函数而不是 getString() 函数将解决该问题。但要小心,因为 getBlob() 函数返回 byte[] 类型的值。要将其转换为字符串,您必须执行以下操作:
Using the getBlob() function instead of the getString() function will solve the problem. Be careful though since the getBlob() function returns a value of type byte[]. To convert this to a string you have to do something like:
您应该使用方法
getBlob(int)
,而不是getString(int)
。请参阅 http://developer.android.com/reference/android /database/Cursor.html#getBlob(int)
You should use the method
getBlob(int)
, notgetString(int)
.See http://developer.android.com/reference/android/database/Cursor.html#getBlob(int)
如何将 BLOB 转换为字符串?
您收到错误的列的数据类型是什么(根据您的说法,我认为这是 URL 列)?听起来像是 BLOB 类型,它是图像的表示,而不是字符串
How to convert BLOB to string?
What is the datatype of the column you are getting the error on (from what you say I think this is the URL column)? Sounds like it is of type BLOB which is a representation of an image but not a string