膨胀 xml 时的 InvokingTargetException - android
我有一个代码,由于部署在很多客户端中,所以 99% 的时间都有效,但有时我会得到以下信息:
java.lang.reflect.InitationTargetException android.widget.LinearLayout。(LinearLayout.java:92) java.lang.reflect.Constructor.constructNative(本机方法) java.lang.reflect.Constructor.newInstance(Constructor.java:446) android.view.LayoutInflater.createView(LayoutInflater.java:499) com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562) android.view.LayoutInflater.rInflate(LayoutInflater.java:617) android.view.LayoutInflater.inflate(LayoutInflater.java:407) android.view.LayoutInflater.inflate(LayoutInflater.java:320) com.mycode.mycode.MyClass.draw(xxxxxxx) ......
在我的代码中我有:
LayoutInflater li = (LayoutInflater) 这个 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
theview = li.inflate(R.layout.partofthescreen, 某些容器,假);
所以问题是为什么我会收到 InvocableTargetException 。
谢谢
I have a code that works 99% of the time since is deploy in lots of clients, but sometimes I get the following:
java.lang.reflect.InvocationTargetException
android.widget.LinearLayout.(LinearLayout.java:92)
java.lang.reflect.Constructor.constructNative(Native Method)
java.lang.reflect.Constructor.newInstance(Constructor.java:446)
android.view.LayoutInflater.createView(LayoutInflater.java:499)
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
android.view.LayoutInflater.inflate(LayoutInflater.java:407)
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
com.mycode.mycode.MyClass.draw(xxxxxxx)
.....
and on my code I have:
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
theview = li.inflate(R.layout.partofthescreen,
somecontainer, false);
so the question is why I am getting InvocationTargetException.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用
getLayoutInflater()
而不是getSystemService()
调用,尽管我不确定这会有所不同。IncationTargetException
来自反射,意味着被调用的Method
抛出了Exception
。您是否看到任何可能是底层异常
的堆栈跟踪迹象?如果没有,请尝试捕获InitationTargetException
并查看getCause()
以了解到底发生了什么。You can try
getLayoutInflater()
instead of yourgetSystemService()
call, though I am not sure that will make a difference.An
InvocationTargetException
comes from reflection, and means theMethod
that was invoked threw anException
. Do you see any sign of another stack trace that might be the underlyingException
? If not, try catchingInvocationTargetException
and looking atgetCause()
to see what is really going on.我也有同样的问题。
我通过以下方式解决了这个问题:
创建局部变量
然后在类构造函数(具有参数上下文上下文)中执行此操作
I also had the same problem.
I solved that problem by:
Make the local variable
Then in your class constructor( which has argument Context context) do this