我正在使用下面的代码。执行Movie.decodeFile(pathName)时 出现 IOException。
Movie movie;
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir,"weather.gif");
String pathName = file.getAbsolutePath();
Log.d("rvg", "Path: "+pathName);
if(file.exists())
{
Log.d("rvg", "image available");
movie=Movie.decodeFile(pathName);
}
else
{
Log.d("rvg", "image not available");
}
Logcat 异常:
08-19 05:55:43.271: D/rvg(1458): Path: /mnt/sdcard/weather.gif
08-19 05:55:43.271: D/rvg(1458): image available
08-19 05:55:43.271: W/System.err(1458): java.io.IOException
08-19 05:55:43.271: W/System.err(1458): at java.io.InputStream.reset(InputStream.java:218)
08-19 05:55:43.271: W/System.err(1458): at android.graphics.Movie.decodeStream(Native Method)
08-19 05:55:43.271: W/System.err(1458): at android.graphics.Movie.decodeTempStream(Movie.java:74)
08-19 05:55:43.271: W/System.err(1458): at android.graphics.Movie.decodeFile(Movie.java:59)
08-19 05:55:43.271: W/System.err(1458): at com.android.gif.GIFDemo$GIFView.<init>(GIFDemo.java:64)
08-19 05:55:43.271: W/System.err(1458): at com.android.gif.GIFDemo$1.run(GIFDemo.java:36)
08-19 05:55:43.271: W/System.err(1458): at android.os.Handler.handleCallback(Handler.java:615)
08-19 05:55:43.271: W/System.err(1458): at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 05:55:43.271: W/System.err(1458): at android.os.Looper.loop(Looper.java:137)
08-19 05:55:43.271: W/System.err(1458): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-19 05:55:43.271: W/System.err(1458): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 05:55:43.271: W/System.err(1458): at java.lang.reflect.Method.invoke(Method.java:511)
08-19 05:55:43.271: W/System.err(1458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-19 05:55:43.271: W/System.err(1458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-19 05:55:43.271: W/System.err(1458): at dalvik.system.NativeStart.main(Native Method)
我想从 sdcard 加载 gif 图像。如何解决这个问题?如果是可绘制文件夹中的 gif 图像。它运作良好。但无法从 sdcard 加载。给我解决方案。