分贝的android我是做一个应用程序在SQLite数据库中插入数据和ii有一个空指针异常时记录添加到数据库空指针异常时嵌入照片中的Android
这个初学者代码得到的ImageView的PIC,并将其转换再到位图以字节来保存 任何建议,以避免此异常 这里是代码
imageView1.setDrawingCacheEnabled(true);
imageView1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imageView1.layout(0, 0, imageView1.getMeasuredWidth(), imageView1.getMeasuredHeight());
imageView1.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(imageView1.getDrawingCache());
imageView1.setDrawingCacheEnabled(false);
save_picture=loginDataBaseAdapter.getBytes(b);
loginDataBaseAdapter.insertEntry(userName, password, save_picture);
Toast.makeText(getApplicationContext(), "Record created ", Toast.LENGTH_LONG).show();`}
有转换位为字节的方法
// convert from bitmap to byte array
public byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
press(CompressFormat.PNG, 0, stream);
return stream.toByteArray();
}
并没有插入方法
public void insertEntry(String userName,String password , byte[] photo )
{
ContentValues newValues = new ContentValues();
// Assign values for each row.
newValues.put("USERNAME", userName);
newValues.put("PASSWORD",password);
newValues.put("Photo", photo);
// Insert the row into your table
db.insert("LOGIN", null, newValues);
}
和存在的DB创建
static final String DATABASE_CREATE = "create table "+"LOGIN"+
"(" +"ID"+" integer primary key autoincrement,"+ "USERNAME text,PASSWORD text, Photo blob not null); ";
感谢
-12-29
BOB91
+0
我们能看到错误输出? –
+1
可能重复[什么是空指针异常,以及如何解决它?](/questions/218384/what-is-a-null-pointer-exception-and-how-do -i-fix-it) –
+0
E/AndroidRuntime(15303):致命例外:main E/AndroidRuntime(15303):java.lang.NullPointerException E/AndroidRuntime(15303):\t at android.graphics.Bitmap.createBitmap( Bitmap.java:571) E/AndroidRuntime(15303):\t at com.techblogon.loginexample.SignUPActivity $ 1.onClick(SignUPActivity.java:91) E/AndroidRuntime(15303):\t at android.view.View.performClick (View.java:2532) 这里是错误 –
如果觉得《android 拍照空指针 空指针异常时嵌入照片中的Android》对你有帮助,请点赞、收藏,并留下你的观点哦!