在我的android项目中,我在从数据库中检索数据时遇到了一个问题。 在这里我尝试从URL获取字符串值,如URL,但当此代码执行时,我得到此错误 android.database.sqlite.SQLiteException:未知错误:无法将BLOB转换为字符串 只有URL colomn给我这个错误,而不是任何其他字符串colomn。
我没有得到我错的地方。所以朋友请给我建议我如何解决这个问题。在这里,我也打印我的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)
答案 0 :(得分:3)
使用getBlob()函数而不是getString()函数将解决问题。但请注意,因为getBlob()函数返回byte []类型的值。要将其转换为字符串,您必须执行以下操作:
String words = "";
try {
words = new String(words_blob, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 1 :(得分:1)
您应该使用方法getBlob(int)
,而不是getString(int)
。
请参阅http://developer.android.com/reference/android/database/Cursor.html#getBlob(int)
答案 2 :(得分:0)
How to convert BLOB to string?
如果不使用某些UDF,则无法进行直接转换,但您可以 使用SUBSTRING函数提取文本:
您收到错误的列的数据类型是什么(从您说我认为这是URL列)?听起来像是BLOB类型,它是图像的表示,但不是字符串