我有一个代码在 99% 的时间内都有效,因为它部署在许多客户端中,但有时我会得到以下信息:
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) .....
在我的代码中我有:
LayoutInflater li = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
theview = li.inflate(R.layout.partofthescreen, somecontainer, false);
所以问题是为什么我会收到 InvocationTargetException。
谢谢
最佳答案
您可以尝试使用 getLayoutInflater()
来代替您的 getSystemService()
调用,但我不确定这是否会产生影响。
InvocationTargetException
来自于反射,意味着被调用的Method
抛出了一个Exception
。您是否看到任何可能是底层 Exception
的堆栈跟踪迹象?如果没有,请 try catch InvocationTargetException
并查看 getCause()
以了解实际情况。
关于xml - 关于膨胀 xml 的 InvocationTargetException - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2417341/