Robolectric 1.1 fails to load layout file when the file is not in the directory res/layout/

46 views
Skip to first unread message

Robson R Ferreira

unread,
Nov 8, 2012, 3:10:45 PM11/8/12
to robol...@googlegroups.com
when I run the tests in robolectric 1.1 the following error occurs when inflate a layout file:

java.lang.RuntimeException: Could not find layout layout/home_layout
       at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:92)
       at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:82)
       at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:86)

Does anyone know why this error occurs? from what I saw, in version 1.1 of robolectric was no change in the way of loading layout files, it searches the folder layout/:

   private ViewNode getViewNodeByLayoutName(String layoutName) {
        if (layoutName.startsWith("layout/") && !qualifierSearchPath.isEmpty()) {
            String rawLayoutName = layoutName.substring("layout/".length());
            for (String location : qualifierSearchPath) {
                ViewNode foundNode = viewNodesByLayoutName.get("layout-" + location + "/" + rawLayoutName);
                if (foundNode != null) {
                    return foundNode;
                }
            }
        }
        return viewNodesByLayoutName.get(layoutName);
    }

but if the layout file is in another directory (eg layout-normal-hdpi), this error will occur ..

Does anyone know any solution for this?

Reply all
Reply to author
Forward
0 new messages