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 7419585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:48+00:00 2026-05-29T08:05:48+00:00

I have a EditText on my View and I would like to set a

  • 0

I have a EditText on my View and I would like to set a onKeyListener.

Here is my code:

final EditText edittext = (EditText) findViewById(R.id.editText1);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    edittext.setOnKeyListener(new EditText.OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {

            return false;
        }
    });   
}

The problem is that i have problems with this, here is a error part of the logcat:

W/dalvikvm(3703): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(3703): FATAL EXCEPTION: main
E/AndroidRuntime(3703): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{milos.mdpi/milos.mdpi.MDPIActivity}: java.lang.NullPointerException
E/AndroidRuntime(3703):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
E/AndroidRuntime(3703):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime(3703):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(3703):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime(3703):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(3703):     at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(3703):     at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(3703):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(3703):     at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(3703):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(3703):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(3703):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(3703): Caused by: java.lang.NullPointerException
E/AndroidRuntime(3703):     at android.app.Activity.findViewById(Activity.java:1647)
E/AndroidRuntime(3703):     at milos.mdpi.MDPIActivity.<init>(MDPIActivity.java:22)
E/AndroidRuntime(3703):     at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(3703):     at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime(3703):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(3703):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
E/AndroidRuntime(3703):     ... 11 more
  • 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-05-29T08:05:49+00:00Added an answer on May 29, 2026 at 8:05 am
    private EditText edittext;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.<yourlayout>.xml);
        edittext = (EditText) findViewById(R.id.editText1);
    
        edittext.setOnKeyListener(new EditText.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
    
                return false;
            }
        });
    }
    

    if the problem persists, and you still get NPE, your EditText probably have other id in your layout xml.

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

Sidebar

Related Questions

In my view, I have a search EditText and I would like to trigger
I have a scroll view that I would like to fill the whole screen,
I have an EditText and a Button set next to each other on the
I have this nice dialog view I set my UserInputDialog class to: <LinearLayout android:id=@+id/LinearLayout01
I have a layout which has one large EditText view at the top +
I have a gridview with the onRowDeleting method implemented. I would like to prompt
I have a blank button on which I would like to assign a name,
I have a activity, which view have a several EditText components. When activity starts,
Im trying to compare the values of two edittext boxes. What i would like
I have an EditText view in my xml file with a certain width. I

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.