question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'can not access a member' exception

See original GitHub issue

My setup is :

public class RoboElectricDaggerMockRule extends DaggerMockRule<TestAppComponent> {
    public RoboElectricDaggerMockRule() {
        super(TestAppComponent.class, new AssistantUtilsModule());
        customizeBuilder(new BuilderCustomizer<TestAppComponent.Builder>() {
            @Override public TestAppComponent.Builder customize(TestAppComponent.Builder builder) {
                return builder.application(getApp());
            }
        });
        set(new DaggerMockRule.ComponentSetter<TestAppComponent>() {
            @Override public void setComponent(TestAppComponent component) {
                component.inject(getApp());
            }
        });
    }

    private static AnydoRobolectricTestApp getApp() {
        return (AnydoRobolectricTestApp) RuntimeEnvironment.application;
    }
}

My test configuration :

@RunWith(RobolectricTestRunner.class)
@Config(application = AnydoRobolectricTestApp.class,constants = BuildConfig.class, sdk = 21, shadows = { ShadowPreferenceHelper.class})
public class DeepLinkTestNew {


    @Rule public RoboElectricDaggerMockRule rule = new RoboElectricDaggerMockRule();

    @Mock
    AssistantUtils assistantUtils;
    
    @Test
    `public void testSomething()`

public interface TestAppComponent extends AndroidInjector<AnydoRobolectricTestApp> {

    @Override
    void inject(AnydoRobolectricTestApp instance);

    @Component.Builder
    interface Builder {

        Builder assistantUtilsModule(AssistantUtilsModule assistantUtilsModule);

        @BindsInstance
        TestAppComponent.Builder application(Application application);

        TestAppComponent build();
    }
}

But I get the following error : image

“java.lang.IllegalAccessException: Class it.cosenonjaviste.daggermock.ObjectWrapper can not access a member of class com.anydo.di.components.DaggerTestAppComponent$Builder with modifiers “public””

TestAppComponent which is auto generated by Dagger has all fields private, so it makes sense. Am I missing something ?

And another question, is it mandatory to add a module setter like this inside the component? Builder assistantUtilsModule(AssistantUtilsModule assistantUtilsModule); it’s kinda boilerplate and would be great if we can remove.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
fabioCollinicommented, Oct 9, 2017

I have pushed a new version to fix this issue, I have tried here and it seems to work. Can you try the version cc0b0acd98 to confirm that this commit fixes your error as well? Thanks again for your help

0reactions
fabioCollinicommented, Oct 16, 2017

I have just released version 0.8.2 to include this fix, thanks again for your report and for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

can not access a member of class org.springframework.aop ...
This class is not public itself. It is package protected (see here). You have to call setAccessible(true) before access its member exactly ...
Read more >
can not access a member of class with modifiers "public"
I get this error: [quote]java.lang.IllegalAccessException: Class com.vaadin.data.util.MethodProperty can not access a member of class ...
Read more >
Can not access a member of class X with modifiers "public ...
When upgrading from 1.4 to 1.5 none of my template is working anymore. For example : [javadoc] ERROR [console:logVelocityMessage] - ASTMethod.execute() ...
Read more >
Troubleshooting (The Java™ Tutorials > The Reflection API ...
This reflection Java tutorial describes using reflection for accessing and ... IllegalAccessException: Class ClassTrouble can not access a member of class ...
Read more >
System.MemberAccessException Class - GNU.org
MemberAccessException.Message property of the new instance to a system-supplied message that describes the error, such as "Cannot access member.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found