Pregunta

Tengo un código que funciona el 99% del tiempo debido a que se despliegue en una gran cantidad de clientes, pero a veces me sale el siguiente:

  

java.lang.reflect.InvocationTargetException     android.widget.LinearLayout. (LinearLayout.java:92)       java.lang.reflect.Constructor.constructNative (Nativo Método)       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)   .....

y en mi código que tengo:

  

li LayoutInflater = (LayoutInflater) esta                       .getSystemService (Context.LAYOUT_INFLATER_SERVICE);
              theview = li.inflate (R.layout.partofthescreen,                       somecontainer, false);

Así que la pregunta es ¿por qué estoy recibiendo InvocationTargetException.

Gracias

¿Fue útil?

Solución

Puede intentar getLayoutInflater() en lugar de su llamada getSystemService(), aunque no estoy seguro de que hará una diferencia.

Una InvocationTargetException proviene de la reflexión, y el medio de Method que fue invocado lanzó una Exception. ¿Ve alguna señal de otro seguimiento de pila que podría ser el Exception subyacente? Si no es así, tratar de atrapar InvocationTargetException y mirando a getCause() para ver lo que realmente está pasando.

Otros consejos

también tenía el mismo problema.

He resuelto este problema por:

Hacer la variable local

private Context **context**;

A continuación, en el constructor de la clase (que tiene argumento contexto Contexto) hacer esto

this.context=**context**;

LayoutInflater li = (LayoutInflater) **context** .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

theview = li.inflate(R.layout.partofthescreen, somecontainer, false);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top