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

  • SEARCH
  • Home
  • 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 7008053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:41:10+00:00 2026-05-27T21:41:10+00:00

I created a class to extend KeyEvent: public class myKeyEvent extends KeyEvent { public

  • 0

I created a class to extend KeyEvent:

public class myKeyEvent extends KeyEvent {
    public static final int MY_KEYCODE_01 = KeyEvent.KEYCODE_A;
    //...
    public static final int MY_KEYCODE_30 = KeyEvent.KEYCODE_Z;
}

Now, i want to get the Integer value by the variable name (eg. “MY_KEYCODE_01” should return integer value KeyEvent.KeyCODE_A) from another class (another file).

I tried to:

try{
    Class cls = myKeyEvent.class.getClass();
    Field field = cls.getDeclaredField("MY_KEYCODE_01");
    int value = (Integer) field.get(cls);
    Log.v("TAG", "Field value is " + value);

} catch (NoSuchFieldException e) {
    Log.e("TAG", "Field either doesn't exist or is not public: " + e.toString() );
}

In LogCat:

Field either doesn't exist or is not public: java.lang.NoSuchFieldException: MY_KEYCODE_01

How can I do it?

  • 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-27T21:41:11+00:00Added an answer on May 27, 2026 at 9:41 pm

    The class is myKeyEvent.class if you do myKeyEvent.class.getClass() you are getting the class of the class object which is Class. Drop the getClass()

    You should be able to see the class is not correct in a debugger.

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

Sidebar

Related Questions

I created a class that extends ProfileBase: public class CustomerProfile : ProfileBase { public
public class testMultiAutoCompleteTextView extends ListActivity { /** Called when the activity is first created.
I created class ChImage from UIImage @interface ChImage : UIImage { @public int ChannelId;
Tearing my hair out. I created an as3 class - blah.Foo, which extends MovieClip.
I've created class that takes Exception type in constructor private readonly Exception _exception; public
I created a class that's something like this: public class MovieTheaterList { public DateTime
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends
My java class file looks like public class SignIn extends Activity { /*** Called
Hi All I have the following code: enter code here public class XMPPClient extends
I've created a partial class to extend the default spmetal class to handle publishing

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.