Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:19:15+00:00 2026-06-18T09:19:15+00:00

For some reason, it is trying to bring up a context menu when I

  • 0

For some reason, it is trying to bring up a context menu when I long press an EditText box (such as to paste in data).

Here is LogCat:

01-26 12:00:22.243: E/AndroidRuntime(22300): FATAL EXCEPTION: main
01-26 12:00:22.243: E/AndroidRuntime(22300): java.lang.NullPointerException
01-26 12:00:22.243: E/AndroidRuntime(22300):    at com.---.---.Comments.onCreateContextMenu(Comments.java:352)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View.createContextMenu(View.java:7781)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View.createContextMenu(View.java:7789)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View.createContextMenu(View.java:7789)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at com.android.internal.view.menu.ContextMenuBuilder.show(ContextMenuBuilder.java:81)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at com.android.internal.policy.impl.PhoneWindow$DecorView.showContextMenuForChild(PhoneWindow.java:2201)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2969)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:612)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View.showContextMenu(View.java:4154)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View.performLongClick(View.java:4123)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.widget.TextView.performLongClick(TextView.java:7875)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.view.View$CheckForLongPress.run(View.java:16945)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.os.Handler.handleCallback(Handler.java:615)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.os.Looper.loop(Looper.java:137)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at android.app.ActivityThread.main(ActivityThread.java:4745)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at java.lang.reflect.Method.invoke(Method.java:511)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-26 12:00:22.243: E/AndroidRuntime(22300):    at dalvik.system.NativeStart.main(Native Method)
01-26 12:00:22.250: W/ActivityManager(291):   Force finishing activity com.---.rat---/.Comments

The code of my ContextMenu with line causing NullPointer:

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    android.view.MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.comments_context, menu);
    menu.setHeaderTitle("Available Actions");

    android.view.MenuItem Edit = menu.findItem(R.id.editComment);
    android.view.MenuItem Delete = menu.findItem(R.id.deleteComment);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    int position = info.position;
    ListView lv = (ListView) v;
    int firstVisible = lv.getFirstVisiblePosition();
    View rowView = lv.getChildAt(position - firstVisible);

  // this is the line where there is a null pointer.  (Obviousness in an `EditText` box,  this `TextView` doesn't exist!

    ReviewUser = ((TextView) rowView.findViewById(R.id.labelReviewCommentUser)).getText().toString();
    ReviewComment = ((TextView) rowView.findViewById(R.id.labelReviewComment)).getText().toString();


    // Other Stuff Edited Out

}

The EditText box is created in my onCreate:

EtComment = (EditText) findViewById(R.id.etTweetComment);

At the very end of onCreate is this:

registerForContextMenu(getListView());

Also, just above where I declare the EditText, I setup listview:

LayoutInflater inflater = this.getLayoutInflater();
        ViewGroup header = (ViewGroup) inflater.inflate(
                R.layout.comment_header, listView, false);

        listView = getListView();
        listView.addHeaderView(header, null, false);
        listView.setClickable(false);
        listView.setTextFilterEnabled(true);

The EditText Box is in the ListView header (comment_header). Not sure if that matters.

Main Question: Why is it trying to register a ContextMenu by longpressing an EditText?

EDIT/UPDATE:

I beleive CommonsWare answers this now I am struggling with code for it:

Please compare v with getListView() to see if they are the same
object or not. If they are not, just chain to the superclass.

How do you achieve this? When I call this, registerForContextMenu(getListView()); I believe, it will ALWAYS open the ContextMenu with the ListView in mind based on that code, so how can I do the comparison whether I am long pressing a ListView vs an EditText box?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:19:16+00:00Added an answer on June 18, 2026 at 9:19 am

    It can pop-up a ContextMenu dialog to handle long press on the EditText widget. Generally this menu would contain things like:

    • Cut
    • Copy
    • Paste
    • Select All
    • Select Text

    The action taken when longpressing on the EditText is dependent on the device you are running on due to various differences in the platform versions, and OEM ui’s that get implemented across the range of devices. So without knowing more about what device you are on I can only give a general idea of why the OS could be popping up a context menu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying this and for some reason is not working. I'm suspecting it may
I'm trying to write a Counting sort function but for some reason it's getting
I am trying to learn codeigniter and for some reason I can't do the
I am trying to validate email using javascript but for some reason it is
For some reason I can't hide WPF Toolkit's DataGridColumn. I am trying to do
For some reason, I'm having a hard time trying to cover the block of
I am trying to encrypt and decrypt some simple text. But for some reason
Im trying to get this working but for some reason it's just not right.
I'm trying to start a phantomjs process from python but for some reason it's
I am trying to remove a button from a list and for some reason

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.