robolectric using with android annotation getting exception

118 views
Skip to first unread message

Kasun Samaranayake

unread,
Apr 15, 2015, 1:48:09 AM4/15/15
to robol...@googlegroups.com

,When I use android annotations always gettina exception called Resources$NotFoundException for the button that is created in login activity using annotations.Here is the code that I m using for test,is there a solution for this , I put the exception in below 


@RunWith(RobolectricTestRunner.class)
@Config(manifest = "src/main/AndroidManifest.xml", emulateSdk = 18)
public class DeckardActivityTest {

    @ViewById(R.id.btnLogin)
    Button button;
    @Test
    public void testSomething() throws Exception {
       assertTrue(Robolectric.buildActivity(LoginActivity.class).create().get() != null);
        LoginActivity_ activity = Robolectric.setupActivity(LoginActivity_.class);
        Button button1 = (Button) activity.findViewById(R.id.btnLogin);

      


    }
}

     android.content.res.Resources$NotFoundException: unknown resource 2130903072
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:311)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:92)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1114)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2304)
at android.content.res.Resources.getLayout(Resources.java:934)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
     at android.app.Activity.setContentView(Activity.java:1895)
 

Csaba Kozák

unread,
Apr 16, 2015, 4:13:22 PM4/16/15
to robol...@googlegroups.com
I doubt this problem is related to AndroidAnnotations.

I suggest to search your R classes to see what resource is missing exactly (2130903072).

Another thing: AndroidAnnotations annotations do not work inside test classes... So remove this part:

@ViewById(R.id.btnLogin)
Button button;

Reply all
Reply to author
Forward
0 new messages