NullPointerException due to long press on TextView

I found this strange error thanks to Crashlytics and it happened with the Samsung G386T. The Android application includes new android.support.v7 class classes to include a toolbar component. Unfortunately the error is very "generic" and it does not name the classes in my application where the error was started.

An example of a user activity declaration:

public class AccessAccountActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.access_acount_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        toolbar.setLogo(R.drawable.ic_toolbar);
        setSupportActionBar(toolbar);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(getString(R.string.app_name));
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

      

}

Gradle (Android Studio):

compile 'com.android.support:appcompat-v7:21.0.2'

[Error tracing]

java.lang.NullPointerException
   at android.widget.Editor.performLongClick(Editor.java:1010)
   at android.widget.TextView.performLongClick(TextView.java:10153)
   at android.view.View$CheckForLongPress.run(View.java:19434)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:146)
   at android.app.ActivityThread.main(ActivityThread.java:5692)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
   at dalvik.system.NativeStart.main(NativeStart.java)

      

+3


source to share


2 answers


Hi you have to use return value for longClick (TRUE)



editText.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        return true;
                    }
                });

      

0


source


Check if you are doing some other action in the textview..i ran into a similar problem and I found out that along with the long print I was doing another action (like showing a dialog, etc.), due to which this error was occurring. try not to do this .. or set a timer. Please note that for me this only happened on the Lollipop versions of Samsung reported by the crashes.



0


source







All Articles