【问题标题】:why the app crashing when i open the app? [closed]为什么我打开应用程序时应用程序崩溃? [关闭]
【发布时间】:2021-11-07 20:08:19
【问题描述】:

这段代码有什么问题,因为当我在设备中打开应用程序时,应用程序会崩溃

    private void insertWhereAreYou() {
        String firstNameString = mFirstName.getText().toString().trim();
        String lastNameString = mLastName.getText().toString().trim();
        String ageString = mAge.getText().toString().trim();
        String descriptionString = mDescription.getText().toString().trim();

        byte[] image = imageViewToByte(mInsertImage);
        int age = Integer.parseInt(ageString);

        ContentValues values = new ContentValues();
        values.put(WhereAreYouEntry.COLUMN_FIRST_NAME, firstNameString);
        values.put(WhereAreYouEntry.COLUMN_LAST_NAME, lastNameString);
        values.put(WhereAreYouEntry.COLUMN_DESCRIPTION, descriptionString);
        values.put(WhereAreYouEntry.COLUMN_AGE, age);
        values.put(WhereAreYouEntry.COLUMN_IMAGE, image);

        Uri newUri = getContentResolver().insert(WhereAreYouEntry.CONTENT_URI, values);
    }

【问题讨论】:

  • 你不能用 bye[] 设置ImageResource,我假设那里有一个位图(这本身有点奇怪,除非你从内容提供者而不是数据库中获取它),你有使用 BitmapFactory.decodeBitmap 并在 imageview 上使用位图
  • 你有别的解决办法吗,因为我用的是bindView

标签: java android android-studio


【解决方案1】:

需要将图片字节转成bimap,然后设置成imageview

  byte[] image = cursor.getBlob(imageColumnIndex);
    Bitmap bm = BitmapFactory.decodeByteArray(image, 0, image.length);
    imageView.setImageBitmap(image);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 2011-07-16
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多