0

I am programming an RSS feed type app and on devices that are older than android 7.0, they will often get an android.util.AndroidRuntimeException and I cannot quite figure out why they are getting it. EDIT** The error is happening when a card (using cardview and recyclerview) is clicked on which will take the user to the corresponding URL.

The error itself is:

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:138)
  at com.hillsdalewatch.rssfeed.Adapter.FeedViewHolder.onClick (FeedAdapter.java:52)
  at android.view.View.performClick (View.java:5205)
  at android.view.View$PerformClick.run (View.java:21164)
  at android.os.Handler.handleCallback (Handler.java:745)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

Whereas, FeedAdapter:138 is "mContext.startActivity(i);" which opens another activity that is basically just a webview and i is the url.

FeedAdapter:52 is "itemClickListener.onClick(v, getAdapterPosition(), true);" which is in an onClick method.

The app runs and works perfectly on any device running 7.0 or higher. Is there something I am overlooking that doesn't work on older devices?

  • 1
    Could you add the code for the `onClick()` in the FeedAdapter around line 138? – Xavier Rubio Jansana Dec 29 '17 at 21:49
  • if(Build.VERSION.SDK_INT >= 7.0){ String weblink = new String(rssObject.getItems().get(position).getLink()); Intent i = new Intent(mContext, Browser.class); i.putExtra("URL", weblink); mContext.startActivity(i); } else { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(rssObject.getItems().get(position).getLink())); mContext.startActivity(browserIntent); } – OneEyedNinja Dec 30 '17 at 01:21
  • I don't quite know how to format it in a comment, i do apologize. "mContext.startActivity(i)" is line 138, however. – OneEyedNinja Dec 30 '17 at 01:24
  • Ok, more questions. I understand that `Browser` class is an `Activity` that contains some specific code for Android 7.0+, no? – Xavier Rubio Jansana Dec 30 '17 at 10:41
  • All it is, is a blank activity with a WebView and a toolbar. However that is where the error seems to stem from on older devices so I wanted to try and see if the error was still present when prompted to just open the webpage in chrome. – OneEyedNinja Dec 30 '17 at 12:10
  • The Browser class is just a blank activity with a WebView and a Toolbar. All it does is open the URL passed to it and display it through the WebView. That seems to be where the error is stemming from, so I added the check to try to just open the page in an installed browser on the users phone if the device is less than 7.0 – OneEyedNinja Dec 30 '17 at 12:13
  • First problem is that this check is wrong... it should be `if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {`. Notice that the constant `Build.VERSION_CODES.N` corresponds to a value `24` (this is, API level). So, you're always opening your `Browser` activity. Can you add the following to your question? AndroidManifest.xml (check specifically if `Browser` activity is declared there) Also, is the stack trace in your question complete? Looks like some is missing there... – Xavier Rubio Jansana Dec 30 '17 at 12:56
  • I cannot add the code because I am not at my computer, but the Browser Activity is indeed in the manifest. That is all the stack trace that is shown for my Google developer page. – OneEyedNinja Dec 30 '17 at 15:57
  • But, have you been able to reproduce it? Or the crash is in the Developer console only? Because first step should be reproduce the issue and have as much information as possible (exact OS version, device manufacturer and model, network type...) – Xavier Rubio Jansana Dec 30 '17 at 17:40
  • I have not been able to reproduce it myself. I have users that have it happen to them. The app will crash and say that it has stopped working. From what I have seen, it does it on a Galaxy J3 with android 4.1.1. And on a Galaxy S5 running 6.0 – OneEyedNinja Dec 30 '17 at 19:45
  • You should try to reproduce it, maybe with the emulator. – Xavier Rubio Jansana Dec 30 '17 at 19:53

0 Answers0