10

Okay, so this code works perfectly fine on any other device, but crashes on Samsung devices. I can't seem to figure out why really, but I do know that if I use a TextView it does not crash. Problem is though, that I need an EditText for this field and it can contain multiple links. I've spent the past one day looking for a solution to no avail, so I thought I'd post here:

Note: This seems to work on Nexus and Motorola devices I tested on: Is there some workaround that I may have missed as I'm going to guess samsung played around with how to handle links in EditText boxes?

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
      EditText t3 = (EditText) findViewById(R.id.text3);
      t3.setText(
              Html.fromHtml(
                      "<b>text3:</b>  Text with a " +
                              "<a href=\"http://www.google.com\">link</a> " +
                              "created in the Java source code using HTML."));
      t3.setMovementMethod(LinkMovementMethod.getInstance());

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Here's a look at the stacktrace if that helps:

    03-21 11:17:34.897: E/AndroidRuntime(1810): FATAL EXCEPTION: main
    03-21 11:17:34.897: E/AndroidRuntime(1810): java.lang.NullPointerException
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.widget.Editor.onTouchUpEvent(Editor.java:1927)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.widget.TextView.onTouchEvent(TextView.java:8865)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.View.dispatchTouchEvent(View.java:7817)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2441)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2174)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2441)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2174)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2441)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2174)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2441)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2174)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2326)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1612)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.app.Activity.dispatchTouchEvent(Activity.java:2494)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2274)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.View.dispatchPointerEvent(View.java:8025)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4668)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4556)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4150)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4207)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4176)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4261)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4184)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4318)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4150)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4207)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4176)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4184)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4150)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6302)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6240)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6211)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6382)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.os.MessageQueue.nativePollOnce(Native Method)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.os.MessageQueue.next(MessageQueue.java:132)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.os.Looper.loop(Looper.java:124)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at android.app.ActivityThread.main(ActivityThread.java:5455)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at java.lang.reflect.Method.invokeNative(Native Method)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at java.lang.reflect.Method.invoke(Method.java:525)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    03-21 11:17:34.897: E/AndroidRuntime(1810):     at dalvik.system.NativeStart.main(Native Method)
nitrobuster
  • 321
  • 3
  • 18
  • logcat please? Have you tried it in the emulators? If it does work in some devices and not all, then it is likely that Samsun tweaked things a bit. – ucsunil Mar 21 '14 at 16:19
  • It works on emulators too yes. Though I do need a workaround to get it working on a samsung device. – nitrobuster Mar 21 '14 at 16:23
  • From your logcat, it does indeed look like a Samsung specific problem as there is nothing in there which points to code problems. What was this workaround you had to use to get it up and running on the Samsung device? I'm trying to google this up and I see that Samsung's developer website has a page where they show EditText containing html text but not a link. – ucsunil Mar 21 '14 at 16:33
  • I haven't quite figured a work around, I'm still trying to figure a solution. – nitrobuster Mar 21 '14 at 16:35
  • Interestingly - I have received the same stack trace on a Samsung device when used TextView styled as EditText instead of actual EditText by mistake. – Boris Treukhov Sep 22 '15 at 18:25

1 Answers1

6

Clickable links and copy/paste menu in EditView in android

This post helped me, if anyone is interested in the answer.

Community
  • 1
  • 1
nitrobuster
  • 321
  • 3
  • 18