0
我想將專輯封面加載到圖像視圖中,但是我的代碼無法正常工作並出錯,如何解決我的錯誤?請幫助。將專輯藝術顯示到圖像視圖
ImageView imageView= (ImageView) findViewById(R.id.imageView);
Uri sArtworkUri = Uri.parse("/sdcard/Sqlit/AndroidDownloadManager.mp3");
if (sArtworkUri !=null){
MediaMetadataRetriever mData=new MediaMetadataRetriever();
mData.setDataSource(this,sArtworkUri);
byte art[]=mData.getEmbeddedPicture();
Bitmap image= BitmapFactory.decodeByteArray(art,0,art.length);
imageView.setImageBitmap(image);
}
錯誤
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andriodtime.net/com.andriodtime.net.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.andriodtime.net.MainActivity.initView(MainActivity.java:91)
at com.andriodtime.net.MainActivity.onCreate(MainActivity.java:35)
如何調用** MainActivity.initView ** ..?添加您的MainActivty onCreate方法。 –
@MuthukrishnanRajendran我添加到onCreate,但錯誤。我認爲這段代碼是不正確的** Uri sArtworkUri = Uri.parse(「/ sdcard/Sqlit/AndroidDownloadManager.mp3」); ** –
根據你的日誌,它崩潰在* * 91號線**你可以檢查線路正在做什麼。或者您可以添加該行 –