1

在我的 android 应用程序中,我从联系人获取联系人详细信息,使用以下代码我能够获取姓名和电话号码,但位图代码显示异常

Bitmap bitmap = null;
String image_uri = "";


image_uri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_ID));


if (image_uri != null) {
    System.out.println(Uri.parse(image_uri));
    Log.d("image",image_uri);
    try {
        bitmap = MediaStore.Images.Media.getBitmap(
        this.getContentResolver(),
        Uri.parse(image_uri));
        //      Toast.makeText(getApplicationContext(), ""+bitmap,Toast.LENGTH_LONG).show();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byteArray = stream.toByteArray();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

日志错误:

07-31 06:50:15.114: E/AndroidRuntime(1734): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.androidsqlite/com.androidhive.androidsqlite.AndroidSQLiteTutorialActivity}: java.lang.NullPointerException
07-31 06:50:15.114: E/AndroidRuntime(1734):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-31 06:50:15.114: E/AndroidRuntime(1734):     at dalvik.system.NativeStart.main(Native Method)
07-31 06:50:15.114: E/AndroidRuntime(1734):     at com.androidhive.androidsqlite.AndroidSQLiteTutorialActivity.onCreate(AndroidSQLiteTutorialActivity.java:79)
4

0 回答 0