以下是从解析中获取imagefile的代码,
但它会抛出NullPointerException
。
请告诉我此代码中的错误。
ImgFile - >是解析中的类名 Img - > ImgFile中的列名
imgItem= (ImageView) findViewById(R.id.imageView);
Log.d("after image creation", " null");
ParseObject anotherApplication = new ParseObject("ImgFile");
ParseFile applicantResume = (ParseFile)anotherApplication.get("Img");
applicantResume.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, com.parse.ParseException e) {
if (e == null)
{
Log.d("before image", " null");
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null)
{ imgItem.setImageBitmap(bmp);
// img.setPadding(10, 10, 0, 0);
}
}
else
{
Log.e("paser after downloade", " null");
}
}
});
LogCat错误是:
02-20 16:21:32.435 7666- 7666/com.dsstechnologies.janardanswami E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dsstechnologies.janardanswami/com.dsstechnologies.janardanswami.Allimg}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2268)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:756)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:572)
at miui.dexspy.DexspyInstaller.main(DexspyInstaller.java:171)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.dsstechnologies.janardanswami.Allimg.onCreate(Allimg.java:43)
at android.app.Activity.performCreate(Activity.java:5135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2182)
Allimg.java
public class Allimg extends Activity {
public ImageView imgItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.allimg);
// Parse.enableLocalDatastore(this);
Parse.initialize(this, "",
"");
imgItem= (ImageView) findViewById(R.id.imageView);
Log.d("after image creation", " null");
ParseObject anotherApplication = new ParseObject("ImgFile");
ParseFile applicantResume = (ParseFile)anotherApplication.get("Img");
applicantResume.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, com.parse.ParseException e) {
if (e == null)
{
Log.d("before image", " null");
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
data.length);
if (bmp != null)
{ imgItem.setImageBitmap(bmp);
// img.setPadding(10, 10, 0, 0);
}
}
else
{
Log.e("paser after downloade", " null");
}
}
});
}
}
感谢你......