I am making an RSS feed app using CardView and RecyclerView, but whenever one of the cards is clicked on, the app with crash and give an AndroidRuntimeException that i cannot figure out.
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
if(!isLongClick) {
url = rssObject.getItems().get(position).getLink();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
//String weblink = new String(rssObject.getItems().get(position).getLink());
Intent i = new Intent(mContext, Browser.class);
//i.putExtra("URL", url);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
} else {
//Once I figure out the fix, gonna use this section for older versions
//Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(position).getLink()));
//mContext.startActivity(browserIntent);
Intent i = new Intent(mContext, Browser.class);
mContext.startActivity(i);
}
}
}
});
I also have a button in the toolbar that opens another activity but with a static url, and that page works just fine; the problem occurs whenever the page is called using the ".getLink()" url. The Browser class activity is as follows..
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browser_layout);
toolbar = (Toolbar)findViewById(R.id.toolbar);
toolbar.setTitle("Hillsdale Watch");
setSupportActionBar(toolbar);
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl(FeedAdapter.url);
}
Both pages work perfectly fine on Android 7.0 but not on anything below. Help!
Here is the crash report that shows in the google developer page.
LGE LG X Style (k6b), 1536MB RAM, Android 6.0
android.util.AndroidRuntimeException:
at android.app.ContextImpl.startActivity (ContextImpl.java:672)
at android.app.ContextImpl.startActivity (ContextImpl.java:659)
at android.content.ContextWrapper.startActivity (ContextWrapper.java:331)
at com.hillsdalewatch.rssfeed.Adapter.FeedAdapter$1.onClick (FeedAdapter.java:143)
at com.hillsdalewatch.rssfeed.Adapter.FeedViewHolder.onClick (FeedAdapter.java:52)
at android.view.View.performClick (View.java:5217)
at android.view.View$PerformClick.run (View.java:21349)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5585)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:620)