2

I got an exception in my android app:

06-18 17:57:39.816    6333-6333/com.appsrox.instachat E/InputEventReceiver﹕ Exception dispatching input event.
06-18 17:57:39.816    6333-6333/com.appsrox.instachat E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
06-18 17:57:39.816    6333-6333/com.appsrox.instachat E/MessageQueue-JNI﹕ android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=href (has extras) }
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1781)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
            at android.app.Activity.startActivityForResult(Activity.java:3745)
            at android.app.Activity.startActivityForResult(Activity.java:3706)
            at android.app.Activity.startActivity(Activity.java:4016)
            at android.app.Activity.startActivity(Activity.java:3984)
            at android.text.style.URLSpan.onClick(URLSpan.java:62)
            at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
            at android.widget.TextView.onTouchEvent(TextView.java:7985)
            at android.view.View.dispatchTouchEvent(View.java:8471)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2742)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
            at android.view.View.dispatchPointerEvent(View.java:8666)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
            at android.view.InputEventReceiver.dispatchInputEvent(I
06-18 17:57:39.816    6333-6333/com.appsrox.instachat D/AndroidRuntime﹕ Shutting down VM
06-18 17:57:39.817    6333-6333/com.appsrox.instachat E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.appsrox.instachat, PID: 6333
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=href (has extras) }
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1781)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
            at android.app.Activity.startActivityForResult(Activity.java:3745)
            at android.app.Activity.startActivityForResult(Activity.java:3706)
            at android.app.Activity.startActivity(Activity.java:4016)
            at android.app.Activity.startActivity(Activity.java:3984)
            at android.text.style.URLSpan.onClick(URLSpan.java:62)
            at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
            at android.widget.TextView.onTouchEvent(TextView.java:7985)
            at android.view.View.dispatchTouchEvent(View.java:8471)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2742)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
            at android.view.View.dispatchPointerEvent(View.java:8666)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:
06-18 17:57:39.818    1228-1596/system_process W/ActivityManager﹕ Force finishing activity 1 com.appsrox.instachat/.ChatActivity

This occur when user clicks URL in text. I have a listfragment with a layout containing TextView. I am testing using Android device emulator in Android Studio.

This happens when user clicks URL in text with urls in app. What its about? How could I fix this error if I need Urls be clickable in text?

My android device has a browser. Here is the part where I do TextView html settings:

TextView tvhtml = (TextView) view;
final String html="<a href="http://www.google.com">Go to Google</a>";
tvhtml.setLinksClickable(true);
tvhtml.setMovementMethod (LinkMovementMethod.getInstance());
tvhtml.setText(Html.fromHtml(html));

Here is some snippet code from my app:

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            getListView().setDivider(null);
            getListView().setSelector(R.drawable.selector_items);
            Bundle args = new Bundle();
            args.putString(DataProvider.COL_EMAIL, mListener.getProfileEmail());
            getLoaderManager().initLoader(0, args, this);
            this.postMesagesCAB();
    }
    .....

    ....

    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                switch (view.getId()) {
                    case R.id.text1:
                     TextView tvhtml = (TextView) view;
                     final String html="<a href="http://www.google.com">Go to Google</a>";
                     tvhtml.setLinksClickable(true);
                     tvhtml.setMovementMethod ( LinkMovementMethod.getInstance());
                     tvhtml.setText(Html.fromHtml(html));

    ...}

    private void postMesagesCAB() {
            final ListView listView = getListView();
            listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

            listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                    ((ListView) parent).setItemChecked(position,
                            ((ListView) parent).isItemChecked(position));
                    //view.setBackgroundColor(Color.CYAN);
                return false;
                }
            });
            listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
                //private int nr = 0;

                @Override
                public void onItemCheckedStateChanged(ActionMode mode, int position,
                                                      long id, boolean checked) {
                    // Here you can do something when items are selected/de-selected,
                    // such as update the title in the CAB
                    Cursor c = ((SimpleCursorAdapter)listView.getAdapter()).getCursor();
                    c.moveToPosition(position);
                    String item = c.getString(0);

                    if (checked) {
                        nr++;
                    } else {
                        nr--;
                    }
                    int fsize=checkedItemPositions.size();
                    mode.setTitle(String.format("%d ite%s selecionado%s", fsize, fsize==1 ? "m" : "ns", fsize==1 ? "" : "s"));
                    mode.invalidate();
                }

...

Luiz Alves
  • 2,575
  • 4
  • 34
  • 75

1 Answers1

8

This occur when user clicks URL in text

In this case, the URL is malformed:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=href (has extras) }

The URL is href. That is not a valid URL.

Here is the part where I do TextView html settings:

That will not compile, as it is not valid Java. You cannot have a quoted string that contains quotes. You need to escape the inner quotes:

final String html="<a href=\"http://www.google.com\">Go to Google</a>";

How could I fix this error if I need Urls be clickable in text?

If you are the one supplying the HTML, make sure that it is valid.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you, Mr Commons Ware. I fix the url and works well. But, Is possible catch the exception when clicking in a invalid url? For now, my app crash when I click in a invalid url. – Luiz Alves Jun 18 '15 at 19:12
  • @LuizAlves: Not with the current code that you have. The thing that is calling `startActivity()` and crashing is the `URLSpan`, which is being created for you via `Html.fromHtml()`. You would need to find the occurrences of `URLSpan` and replace them with your own clone that handles the exception. – CommonsWare Jun 18 '15 at 19:18
  • Thank you for your help. It will possible you point me an alternative link with solution to override URLSpan? I found in stack overflow this code: private void fixTextView(TextView textView) { final SpannableString current = new SpannableString(textView.getText()); final URLSpan[] spans = current.getSpans(0, current.length(), URLSpan.class); int start, end; for (URLSpan span : spans) { start = current.getSpanStart(span); end = current.getSpanEnd(span); current.removeSpan(span); current.setSpan(new DefensiveURLSpan(span.getURL()), start, end, 0); } } – Luiz Alves Jun 18 '15 at 19:45
  • and private static class DefensiveURLSpan extends URLSpan { public DefensiveURLSpan(String url) { super(url); } @Override public void onClick(View widget) { try { android.util.Log.d(getClass().getSimpleName(), "Got here!"); super.onClick(widget); } catch (ActivityNotFoundException e) { // do something useful here // android.text.SpannedString cannot be cast to android.text.SpannableString } } } – Luiz Alves Jun 18 '15 at 19:45
  • I changed my code to : tvhtml.setMovementMethod(LinkMovementMethod.getInstance()); Spanned htmlSpan = Html.fromHtml(html, p, null); fixTextView(tvhtml); tvhtml.setText(htmlSpan); but the crash still occur. – Luiz Alves Jun 18 '15 at 19:46
  • Yes, I did. It was a problem with url. – Luiz Alves Jul 10 '15 at 11:40