0

I have a library(LIB2) project that depends on another library(LIB1) project that I compiled as AAR and uploaded on Archiva.

When I try to start a LIB1 Activity from LIB2 by using:

startActivity(new Intent(HelperActivity.this, xx.company.blabla.package.login.LoginActivity.class));

I get:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

So I did some research and I tried the solutions found here: Error calling Android activity from .aar library. and here: Using an Android library project Activity within another project.

Now, if I do, as suggested by the solutions that I've found,

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("xx.company.blabla.package.login",
            "xx.company.blabla.package.login.LoginActivity"));
startActivity(intent);

and in AndroidManifest.xml

<activity android:name="xx.company.blabla.package.login.LoginActivity"/>

I get error ActivityNotFoundException

Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {xx.company.blabla.package.login/xx.company.blabla.package.login.LoginActivity}; have you declared this activity in your AndroidManifest.xml?

The fact is that I indeed declared the Activity in the Manifest so I can't understand why it does not see it.

Any solutions? Thanks.

xuzhian
  • 1
  • 3

1 Answers1

0

When you use:

intent.setComponent(new ComponentName("xx.company.blabla.package.login",
            "xx.company.blabla.package.login.LoginActivity"));

Android will find package xx.company.blabla.package.login later set it is folder container package xx.company.blabla.package.login; finally find class LoginActivity. Try:

try {
    Class classLoginActivity = Class.forName("xx.company.blabla.package.login.LoginActivity");

    startActivity(new Intent(HelperActivity .this, classLoginActivity));
}catch (Exception e){

}

Hope it can help you!

Dungnbhut
  • 176
  • 5
  • I get NullPointerException. java.lang.RuntimeException: Unable to start activity ComponentInfo{xx.company.blabla/xx.company.blabla.package.login.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference – xuzhian Oct 04 '17 at 13:36
  • Maybe you has error config library. Android can't find your library. – Dungnbhut Oct 04 '17 at 14:57