我java.sql.Blob
在 MySql 数据库中使用图像类型。当我尝试在数据库中插入对象时,出现异常“Java.lang.NullPointerException”
@Override
protected Object doInBackground(Object...arg0) {
try {
Bitmap photo = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
Users user = new Users();
user.setName("haris");
try {
Blob blo = null;
blo.setBytes(1, getBytes(photo));
} catch (Exception e) {
System.out.println("Error:" + e.toString());
}
if (UserService.register(user)) {
System.out.println("Successful registrationl");
} else {
System.out.println("API call wasn't successful");
}
} catch (Exception e) {
System.out.println("Error:" + e.toString());
}
return null;
}
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}