我必须进行一些易碎的测试,而且有时会遇到机器人手枪的一个例外
Caused by: java.lang.NullPointerException
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:44)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at com.jayway.android.robotium.solo.ViewFetcher.getTopParent(ViewFetcher.java:46)
at com.jayway.android.robotium.solo.PublicViewFetcher.getTopParent(PublicViewFetcher.java:6)
at query.Query.rootViews(Query.java:113)
at query.Query.executeQuery(Query.java:29)
这是robotium的getTopParent方法:
/**
* Returns the absolute top parent {@code View} in for a given {@code View}.
*
* @param view the {@code View} whose top parent is requested
* @return the top parent {@code View}
*/
public View getTopParent(View view) {
if (view.getParent() != null // line 44
&& view.getParent() instanceof android.view.View) {
return getTopParent((View) view.getParent()); // line 46
} else {
return view;
}
}
据我所知,这意味着view.getParent()在null检查和从视图的递归调用之间更改为null?
我可以想象向robotium发出拉请求,将getTopParent更改为:
/**
* Returns the absolute top parent {@code View} in for a given {@code View}.
*
* @param view the {@code View} whose top parent is requested
* @return the top parent {@code View}
*/
public View getTopParent(View view) {
final ViewParent parent = view.getParent();
if (parent != null && parent instanceof android.view.View) {
return getTopParent((View) parent);
} else {
return view;
}
}
但我想在此之前有更多意见。
最佳答案
现在,此更改已在机械人主机上进行:
https://github.com/RobotiumTech/robotium/commit/a004cf8cd012709b606590079d5667e519c0d25b
https://github.com/RobotiumTech/robotium/commit/f6b8c9998bf1fe04dd7ff838aab7cdb703cc483e
更多内容:
https://groups.google.com/forum/#!topic/robotium-developers/egAxzgsRYZI
关于android - 机器人室内的NPE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23519395/