我有一个 Android Runtime Fatal Exception: main 我不知道我必须做什么来解决这个问题。我有以下代码,导致此异常:
... @Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Cursor c = (Cursor) mAdapter.getItem(position);
// startActivity(new Intent(Intent.ACTION_VIEW,
// Uri.parse(c.getString(c.getColumnIndex("link")))));
// Cursor c = (Cursor) mAdapter.getItem(position);
// String urlWebView =
// Uri.parse(c.getString(c.getColumnIndex("link"))).toString();
String feedDescription = Uri.parse(
c.getString(c.getColumnIndex("description"))).toString();
String feedTitle = Uri.parse(c.getString(c.getColumnIndex("title")))
.toString();
String feedLink = Uri.parse(c.getString(c.getColumnIndex("link")))
.toString();
String imageLink = Uri.parse(c.getString(c.getColumnIndex("img_link"))).toString();
Intent in = new Intent(MainActivity.this, ShowNewsSummary.class);
in.putExtra("FeedDescription", feedDescription);
in.putExtra("FeedTitle", feedTitle);
in.putExtra("FeedLink", feedLink);
in.putExtra("ImageLink", imageLink);
startActivity(in);
}
在这段代码中,我得到一个 img_link,当在数据库中找不到图像链接时,它可以为空。当我单击一个项目时ShowNewsSummaryActivity
,如果在数据库中找不到 img_link,它会抛出 Fatal Main Exception,因为找不到图像地址时 AsyncTask 无法下载图像:
... @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activty_show_news_summary);
String descriptionFeed = getIntent().getStringExtra("FeedDescription");
String titleFeed = getIntent().getStringExtra("FeedTitle");
imageLinkFeed = getIntent().getStringExtra("ImageLink");
title = (TextView) findViewById(R.id.title_feed);
description = (TextView) findViewById(R.id.description_feed);
imageDescription = (ImageView) findViewById(R.id.descriptionImage);
if (imageDescription != null) {
imageDescription.setVisibility(View.VISIBLE);
new DownloadImageAsyncTask(imageDescription).execute(imageLinkFeed);
}
title.setText(titleFeed);
description.setText(descriptionFeed);
title.setOnClickListener(this);
}
这是异常的LogCat:
09-23 22:54:42.210: E/AndroidRuntime(11885): FATAL EXCEPTION: main
09-23 22:54:42.210: E/AndroidRuntime(11885): java.lang.NullPointerException: uriString
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.net.Uri$StringUri.<init>(Uri.java:464)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.net.Uri$StringUri.<init>(Uri.java:454)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.net.Uri.parse(Uri.java:426)
09-23 22:54:42.210: E/AndroidRuntime(11885): at com.fire147.samplesmartrss.MainActivity.onItemClick(MainActivity.java:176)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3083)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.widget.AbsListView$1.run(AbsListView.java:3983)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.os.Handler.handleCallback(Handler.java:615)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.os.Looper.loop(Looper.java:137)
09-23 22:54:42.210: E/AndroidRuntime(11885): at android.app.ActivityThread.main(ActivityThread.java:4949)
09-23 22:54:42.210: E/AndroidRuntime(11885): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 22:54:42.210: E/AndroidRuntime(11885): at java.lang.reflect.Method.invoke(Method.java:511)
09-23 22:54:42.210: E/AndroidRuntime(11885): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
09-23 22:54:42.210: E/AndroidRuntime(11885): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
09-23 22:54:42.210: E/AndroidRuntime(11885): at dalvik.system.NativeStart.main(Native Method)
我的错误在哪里?