Java 正在Android中获取BLOB数据,null异常

Java 正在Android中获取BLOB数据,null异常,java,android,sqlite,null,blob,Java,Android,Sqlite,Null,Blob,我在Sqlite where BLOB列中插入位图数据(transad byte[]数组)。 我使用此源获取数据 //Get the data byte[] byteArray = helper.getPicture(appWidgetId); //Change byte[] data to Bitmap Bitmap bmPicture = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 但是android显示错误

我在Sqlite where BLOB列中插入位图数据(transad byte[]数组)。
我使用此源获取数据

//Get the data
byte[] byteArray = helper.getPicture(appWidgetId);
//Change byte[] data to Bitmap
Bitmap bmPicture = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
但是android显示错误消息,它的位图为空
所以我添加了检查源代码

//Get the data
byte[] byteArray = helper.getPicture(appWidgetId);
//Check, If byte is not null
if (byteArray != null) {
//Change it to Bitmap
    Bitmap bmPicture = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
}
太完美了…
我不明白为什么添加的“如果源”可以加载数据。
为什么不添加“如果源”无法加载数据。


它看起来像接口…: 添加一些日志记录,并检查您用
if
阻止的情况是否发生/何时发生

if (byteArray != null) {
    //Change it to Bitmap
    Bitmap bmPicture = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    Log.d("TAG", "it worked :)");
} else {
    Log.d("TAG", "it's null :(");
}

我认为你必须调试你的应用程序。在正确的位置设置一些断点,然后继续。这是在运行时计算变量值的最简单方法。我认为这是有问题的:

byte[] byteArray = helper.getPicture(appWidgetId);
显然,这种方法有时并不像预期的那样有效,所以请深入研究这种方法

如果
if
语句没有使错误行为消失,那么只有当
getPicture
方法返回有效结果时,它才会显示成功。如果结果为空,你什么也看不到,对吗

另一个建议是使用异常来判断什么时候出了问题,这样您就可以对意外行为做出反应;-)

是您的助手。getPicture(appWidgetId);异步调用?若并没有,那个么if语句应该并没有什么区别。