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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:08:44+00:00 2026-06-06T05:08:44+00:00

In some case, when accessing an activity field from an anonymous class, I get

  • 0

In some case, when accessing an activity field from an anonymous class, I get NoSuchFieldError at runtime: java.lang.NoSuchFieldError: MyActivity.myField

EDIT: I’m now sure that it’s an Android issue, because everything compiles correctly but resolved incorrectly at runtime. When changing to MyActivity.this.myField instead of plain myField, everything works perfect.

BTW, I rechecked and I don’t have any other myField anywhere else, Also, when opening declaration in Eclipse, it goes to the intended field (myField).

The only problem is that I couldn’t reproduce this in a sample project. I’m left only to state that it’s a specific problem in my project, but I’m reluctant doing so and I can’t publish this project.

I’ll keep this open in case someone stumbles upon something similar.

Here’s the code that I can publish that crashes my project but not the sample one:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new Runnable() {
        @Override
        public void run() {
            Toast.makeText(MyActivity.this, myField.getName(), Toast.LENGTH_SHORT).show();
        }
    }.run();
}
  • 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-06T05:08:45+00:00Added an answer on June 6, 2026 at 5:08 am

    It seems that accessing the field with the class’ prefix solves it: MyActivity.this.myField

    Strange. I guess it’s something with Android’s field resolution in runtime.

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

Sidebar

Related Questions

My code in scala template: @session.get(user.id) match { case Some(_) => xx case _
The use case is some what like this: public class SomeClass : ICloneable {
I'm having some trouble with the idea of accessing variables from other classes. I
I have some code that is accessing Membership.GetUser() to get the current logged in
Having some issues accessing my param tags from within actionscript. Essentially I have the
I have some kind of controller: @Controller public class DefaultController { @RequestMapping(value=/index.html, method=RequestMethod.GET) public
I've some case about executing stored procedures in SQL Server. Maybe it's unusual practice,
I have a queryset containing some objects. Depending on some case or the other
I've been thinking on how the memory would be handled in some specific case
This is a minimal test case of some code that I actually have. It

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.