我正在尝试将图像从字节设置为位图并将其设置为 imageView,但是每当我将其设置为 imageView 时,我都会收到一个空指针异常,对不起,对于一个菜鸟问题,我只是新的字节和位图
这是代码:
iv = (ImageView)findViewById(R.id.imageView1);
fileObject.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// use data for something
Bitmap bmp=BitmapFactory.decodeByteArray(data,0,data.length);
Log.d("test", " "+bmp.toString());
iv.setImageBitmap(bmp); <----- here getting error
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});
iv 在类中本地声明。提前感谢您的帮助。
这是我要求的logcat:
03-06 20:15:46.417: E/AndroidRuntime(388): FATAL EXCEPTION: main
03-06 20:15:46.417: E/AndroidRuntime(388): java.lang.NullPointerException
03-06 20:15:46.417: E/AndroidRuntime(388): at com.shop.browser.ItemInfoActivity$1$1.done(ItemInfoActivity.java:115)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.parse.ParseFile$2.done(ParseFile.java:396)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.parse.GetDataCallback.internalDone(GetDataCallback.java:21)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.parse.GetDataCallback.internalDone(GetDataCallback.java:1)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.parse.BackgroundTask.onPostExecute(BackgroundTask.java:50)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.parse.BackgroundTask.onPostExecute(BackgroundTask.java:1)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.os.Looper.loop(Looper.java:123)
03-06 20:15:46.417: E/AndroidRuntime(388): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-06 20:15:46.417: E/AndroidRuntime(388): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 20:15:46.417: E/AndroidRuntime(388): at java.lang.reflect.Method.invoke(Method.java:521)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-06 20:15:46.417: E/AndroidRuntime(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-06 20:15:46.417: E/AndroidRuntime(388): at dalvik.system.NativeStart.main(Native Method)