ActionBarActivity & ActivityUnitTest - NameNotFoundException

懵懂的女人 提交于 2019-12-02 02:44:46

问题


Ok...it is more likely to be my fault ;)

When I do:

public class XmlLifecycleTests extends ActivityUnitTestCase<Main> {
...
    (not in setUp)
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(APP_PACKAGE);
    intent.setClassName(APP_PACKAGE, ".gui.Main");
    startActivity(intent, null, null);    

I get:

java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{ar.android.app.gui/ar.android.app.gui.GLarmMain}
at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:282)
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:119)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at ar.android.app.gui.Main.onCreate(Main.java:78)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)

Note that my Main activity is defined under .gui while the main package in the manifest is one folder up, this is why I specified everything in the intent. But the thrown error seems to still get the wrong (Package,Class) name pair.


回答1:


It was indeed my fault...switching startActivity to:

setActivity(launchActivity(pkg, actClass, null));

Solved all my problems.



来源:https://stackoverflow.com/questions/21611539/actionbaractivity-activityunittest-namenotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!