我正在尝试从中获取图像URL
,ImageView
我目前正在使用这个类。我已经添加了连接到互联网 write_SD 卡等的权限,问题是当我尝试使用此功能添加图像时AndroidManifest
它返回错误:`java.lang.NullPointerException
ImageView
public void download(String url, ImageView imageView) {
try
{
if (cancelPotentialDownload(url, imageView))
{
//TODO:Caching code right here
String filename = String.valueOf(url.hashCode());
File f = new File(getCacheDirectory(hm), filename);
// Is the bitmap in our cache?
Bitmap bitmap = BitmapFactory.decodeFile(f.getPath());
//No? download it
if(bitmap == null){
BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
imageView.setImageDrawable(downloadedDrawable);
task.execute(url);
}else{
//Yes? set the image
imageView.setImageBitmap(bitmap);
}
}
}catch (Exception e) {
// TODO: handle exception
Log.e("",e.toString());
}
}`
问题是什么可能是错的,我该如何解决这个问题?如果你能指出我正确的方向,我会很高兴。
日志猫:
`06-06 09:38:19.686: E/AndroidRuntime(18832): java.lang.NullPointerException
06-06 09:38:19.686: E/AndroidRuntime(18832): at com.jandans.geos.ImageDownloader.download(ImageDownloader.java:51)
06-06 09:38:19.686: E/AndroidRuntime(18832): at com.jandans.geos.vaikpied$1.onItemClick(vaikpied.java:98)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.widget.ListView.performItemClick(ListView.java:3513)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.os.Handler.handleCallback(Handler.java:587)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.os.Handler.dispatchMessage(Handler.java:92)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.os.Looper.loop(Looper.java:130)
06-06 09:38:19.686: E/AndroidRuntime(18832): at android.app.ActivityThread.main(ActivityThread.java:3835)
06-06 09:38:19.686: E/AndroidRuntime(18832): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 09:38:19.686: E/AndroidRuntime(18832): at java.lang.reflect.Method.invoke(Method.java:507)
06-06 09:38:19.686: E/AndroidRuntime(18832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
06-06 09:38:19.686: E/AndroidRuntime(18832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-06 09:38:19.686: E/AndroidRuntime(18832): at dalvik.system.NativeStart.main(Native Method)
`