Pregunta

Tengo una vista personalizada en src> myproject.test> Homeview

En mi xml principal diseño tengo el siguiente:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_root"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <myproject.test.HomeView
        android:id="@+id/home_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
    </myproject.test.HomeView>

</LinearLayout>

En el HomeActivity tengo una llamada de este tipo en el método onCreate.

setContentView(R.layout.main);
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);

La fuerza de aplicación cerrada cuando se llama al método setContentView. Parece que mi principal XML no es correcto.

¿Alguna idea?

¿Fue útil?

Solución

¿Quiere decir que no es llegar a la

HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);

y estrellarse en la línea antes de que?

Compruebe si su constructor es

HomeView(final Context context, final AttributeSet attrs){
     super(context, attrs);

no

HomeView(final Context context){
     super(context);

se necesita el AttributeSet

Otros consejos

Comprueba los constructores que sus implementos Homeview:

 public HomeView(Context context, AttributeSet atts) {
     super(context, atts); 
 } 
<LinearLayout xmlns:android = 
      http://schemas.android.com/apk/res/android"
    android:id="@+id/home_root"
    android:orientation="vertical"

Ninguno de mis diseños tienen @+id. Tal vez se debe configurar el fin de home_root. Consulte con su R.java para el nombre de la presentación, o tratar

setContentView(R.layout.home_root);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top