我正在尝试用图像构建一个 rss 阅读器,我能够获取提要,但不能从这些提要中获取图像,我已经用*标记了给出空指针异常的行,请帮助,这是我的代码,谢谢。
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.label = (TextView) vi.findViewById(R.id.title);
holder.addr = (TextView) vi.findViewById(R.id.details);
holder.image = (ImageView) vi.findViewById(R.id.thumb);
vi.setTag(holder);
} else
holder = (ViewHolder) vi.getTag();
holder.label.setText(data.get(position).getTitle());
holder.addr.setText(data.get(position).getPubDate());
// imageLoader.DisplayImage((data.get(position).getThumbnail()), holder.image);
URL url = null;
try {
url = new URL((data.get(position).getImage()));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream content = null;
try {
***content = (InputStream)url.getContent();***
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable d = Drawable.createFromStream(content , "src");
Bitmap mIcon1 = null;
try {
mIcon1 =
BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
holder.image.setImageBitmap(Bitmap.createScaledBitmap(mIcon1, 72, 72,true));
return vi;
}
}
日志输出:
error log
06-21 07:16:33.270: E/AndroidRuntime(402): FATAL EXCEPTION: main
06-21 07:16:33.270: E/AndroidRuntime(402): java.lang.NullPointerException
06-21 07:16:33.270: E/AndroidRuntime(402): at com.xmlparse.EfficientAdapter.getView(EfficientAdapter.java:91)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.ListView.makeAndAddView(ListView.java:1727)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.ListView.fillDown(ListView.java:652)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.ListView.fillFromTop(ListView.java:709)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.ListView.layoutChildren(ListView.java:1580)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.View.layout(View.java:7035)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.View.layout(View.java:7035)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.View.layout(View.java:7035)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.View.layout(View.java:7035)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.View.layout(View.java:7035)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.os.Looper.loop(Looper.java:123)
06-21 07:16:33.270: E/AndroidRuntime(402): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-21 07:16:33.270: E/AndroidRuntime(402): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 07:16:33.270: E/AndroidRuntime(402): at java.lang.reflect.Method.invoke(Method.java:521)
06-21 07:16:33.270: E/AndroidRuntime(402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-21 07:16:33.270: E/AndroidRuntime(402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-21 07:16:33.270: E/AndroidRuntime(402): at dalvik.system.NativeStart.main(Native Method)