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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:20:25+00:00 2026-05-26T22:20:25+00:00

I have some code that runs fine in 2.3 and above. However, in 2.2

  • 0

I have some code that runs fine in 2.3 and above. However, in 2.2 I get an NullPointerException when className is getting assigned:

if(field.getType() == java.util.ArrayList.class)
   className = ((ParameterizedType)field.getGenericType()).toString();

EDIT

I did some snooping around on the android docs and found that some of the methods are not available until API level 9. However, getType(), getGenericType(), and ParameterizedType are all said to be supported at API level 1. So why doesn’t this code work?

Field docs: http://developer.android.com/reference/java/lang/reflect/Field.html

ParameterizedType docs: http://developer.android.com/reference/java/lang/reflect/ParameterizedType.html

EDIT

I found out that calling field.getGenericType() does not cause the program to crash, but silently throws a com.sun.jdi.InvocationException. It seems like the Type returned from the call to getGenericType() is not valid? Again, this works on 2.3 and above, but why is this exception being thrown and caught on 2.2 and below?

  • 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-26T22:20:26+00:00Added an answer on May 26, 2026 at 10:20 pm

    This is a known issue, here is the ticket in the Android bug tracker: Issue 6636: NPE in org.apache.harmony.luni.lang.reflect.ListOfTypes

    It was fixed in Android 2.3 but has not been backported to earlier Android releases which is why you see the crash in Android 2.2.

    To be more elaborate: if you run this code (an extended version of your own code) on Android 2.2 :

    public class ReproduceBugActivity extends Activity {
      private static final String TAG = "ReproduceBugActivity";
      private ArrayList<Object> mArrayList;
    
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        try {
          String className = null;
          Field field = getClass().getDeclaredField("mArrayList");
          if (field.getType() == java.util.ArrayList.class)
            className = ((ParameterizedType)field.getGenericType()).toString();
          Log.i(TAG, "className = " + className);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    

    You will get this exception:

    java.lang.NullPointerException
       at org.apache.harmony.luni.lang.reflect.ListOfTypes.length(ListOfTypes.java:47)
       at org.apache.harmony.luni.lang.reflect.ImplForType.toString(ImplForType.java:83)
       at com.reproducebug.ReproduceBugActivity.onCreate(ReproduceBugActivity.java:23)
    

    because of the above mentioned bug in the Java reflection implementation. On Android 2.3, the bug has been fixed, and you’ll see this in the logcat instead:

    I/ReproduceBugActivity(23449): className = java.util.ArrayList<java.lang.Object>
    

    The com.sun.jdi.InvocationException exception your are seeing is unrelated to this as far as I can tell.

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

Sidebar

Related Questions

I have some fairly old code that runs just fine in Excel versions before
I have some code that runs fine when I have a web proxy defined
I have some jQuery code that runs fine until I add the jQuery UI
I have some code that compiles and runs on MSVC++ but will not compile
I have to call some code in a SharePoint site that runs under the
I have the below code that links and runs fine in 32bit mode -
I have some code that disables a trigger on a table, runs an update,
I have some piece of code that runs many times and suddenly reports an
I've written some C++ code that runs perfectly fine on my laptop PC (compiled
I have some code that gives a user id to a utility that then

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.