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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:32:11+00:00 2026-06-11T07:32:11+00:00

I have the following bit of code, used on Android and tested quite extensively

  • 0

I have the following bit of code, used on Android and tested quite extensively about 6 months ago. It has been working fine and has never been the cause of any problems.

private static class CurrentClassGetter extends SecurityManager {
    public String getClassName() {
      return getClassContext()[1].getName();
    }
}

The calling code:

    //---Get my name (last part of class name)
    System.out.println("Attempting to get class name");
    msSimpleName = new CurrentClassGetter().getClassName();

Which, I notice, is the exact same bit of code recommended by someone in this SO answer here:

Getting the class name from a static method in Java

Since this code was written, I’ve updated my Android SDK from r14 to r16. I also downloaded all of the newer SDK packages, from API10 (Android 2.3.3) to API15 (Android 4.0.3). However, the above code which was working fine is now throwing this error:

02-22 16:18:26.779: W/System.err(2593): java.lang.NullPointerException
02-22 16:18:26.786: W/System.err(2593):     at com.company.myCompany.mobile.android.myCompanyApp$CurrentClassGetter.getClassName(myCompanyApp.java:413)
02-22 16:18:26.806: W/System.err(2593):     at com.company.myCompany.mobile.android.myCompanyApp.monitor(myCompanyApp.java:289)
02-22 16:18:26.806: W/System.err(2593):     at com.company.myCompany.mobile.android.myCompanyApp.monitor(myCompanyApp.java:257)
02-22 16:18:26.826: W/System.err(2593):     at com.gomez.appname.appnameActivity.onCreate(appnameActivity.java:22)
02-22 16:18:26.836: W/System.err(2593):     at android.app.Activity.performCreate(Activity.java:4465)
02-22 16:18:26.846: W/System.err(2593):     at android.app.InstAppentation.callActivityOnCreate(InstAppentation.java:1049)
02-22 16:18:26.856: W/System.err(2593):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-22 16:18:26.866: W/System.err(2593):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-22 16:18:26.876: W/System.err(2593):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-22 16:18:26.876: W/System.err(2593):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-22 16:18:26.896: W/System.err(2593):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 16:18:26.896: W/System.err(2593):     at android.os.Looper.loop(Looper.java:137)
02-22 16:18:26.906: W/System.err(2593):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-22 16:18:26.926: W/System.err(2593):     at java.lang.reflect.Method.invokeNative(Native Method)
02-22 16:18:26.926: W/System.err(2593):     at java.lang.reflect.Method.invoke(Method.java:511)
02-22 16:18:26.946: W/System.err(2593):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-22 16:18:26.946: W/System.err(2593):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-22 16:18:26.956: W/System.err(2593):     at dalvik.system.NativeStart.main(Native Method)

Basically, what you’re looking at is a call from onCreate in Android to my private API. Within the API, it’s trying to get the current class name using the above code.

The Target API version was 8 then and it’s 8 now (Android v2.2), so that has not changed at all. Java compliance level 1.6, running Java 1.6.0_24 64-bit.

Does anyone know why getClassContext()[1].getName() would be throwing a NullPointerException like this all of a sudden, when it worked before?

  • 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-11T07:32:12+00:00Added an answer on June 11, 2026 at 7:32 am

    No fix in sight, I ended up removing this block of code entirely. It was only being used in debug output anyway and it wasn’t worth the research to figure out why this was failing.

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

Sidebar

Related Questions

Hi all i have the following bit of code, which is used to generate
I have the following bit of code in a method called by clicking the
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
I have the following bit of code that worked as expected before we upgraded
I have the following bit of code in a class method NSDictionary *shopAddresses =
I have the following bit of code, I expect that given cstdio is included
I have the following bit of code that is timing out when I pass
I have the following bit of code which is responsible for displaying a tooltip.
How do I change the following bit of code so that I only have

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.