-1
所以基本上我試圖生成縮略圖圖像並將其上傳到服務器。所以這是我的代碼,bitmap.compress上的空對象參考
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(intent.getStringExtra("uri"), MediaStore.Video.Thumbnails.MINI_KIND);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
而這是我的uri,我得到了以前活動的uri。它不是空的。
content://com.android.providers.media.documents/document/video%3A28682
但是,當我運行此代碼時,它顯示thumnail.compress方法的nullpointerexception。
錯誤日誌..
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
at com.buckydroid.app.Utils.FirebaseStorage$2.onSuccess(Unknown Source)
at com.buckydroid..Utils.FirebaseStorage$2.onSuccess(Unknown Source)
at com.google.firebase.storage.StorageTask$1.zza(Unknown Source)
at com.google.firebase.storage.StorageTask$1.zzk(Unknown Source)
at com.google.firebase.storage.zze$2.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6126)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
所以我做錯了嗎?
首先,您需要發佈MVCE和堆棧跟蹤。其次,這已經得到了很多次的回答 – efekctive
這個'Intent'裏多了額外的''uri''?你從哪裏得到'Uri'? – CommonsWare
我收到以前的意圖的uri,我添加了日誌消息uri不爲空@CommonsWare – Doge