0
0

java.lang.NullPointerException: uriStringというエラーの対応

Last updated at Posted at 2024-06-30

こちらの記事を参考に実装したところ以下のエラーが出ました。

java.lang.NullPointerException: uriString

こちらを解決した際の内容をかるく紹介しておき、
今後のために記事に残しておきます。

解決方法


for (int i = 0; i < count; i++) {

 val bytes = ByteArrayOutputStream()
 bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
-  val path = MediaStore.Images.Media.insertImage(context.getContentResolver(), 
+  val path = MediaStore.Images.Media.insertImage(context.getContentResolver(), 
 bitmapImage, "Title + i", null)
 val uri = Uri.parse(path)
}

MediaStoreへinsertImageする際にtitleが同じだとエラーになるようで、そこを毎回違う値が入るようにしたらエラーが出なくなりました。

今回はfor文で回していたので、回した回数をtitleに含めて渡すことにしました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0