Пользовательское представление Android вызывает принудительное закрытие - PullRequest
0 голосов
/ 22 октября 2010

У меня есть пользовательское представление в src> myproject.test> HomeView

В моем основном макете XML у меня есть следующее:

<?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>

В HomeActivity у меня есть такой вызовв методе onCreate.

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

Приложение закрывается при вызове метода setContentView.Кажется, что мой основной XML не правильно.

Есть идеи?

Ответы [ 3 ]

2 голосов
/ 22 октября 2010

Ты имеешь в виду, что он не доходит до

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

и сбой на линии до него?

Проверьте, является ли ваш конструктор

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

а не

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

вам нужен набор атрибутов

0 голосов
/ 22 октября 2010
<LinearLayout xmlns:android = 
      http://schemas.android.com/apk/res/android"
    android:id="@+id/home_root"
    android:orientation="vertical"

Ни один из моих макетов не имеет @+id.Может быть, вам следует установить вид на home_root.Уточните у R.java название макета или попробуйте

setContentView(R.layout.home_root);
0 голосов
/ 22 октября 2010

Проверьте конструкторы, которые реализует ваш HomeView:

 public HomeView(Context context, AttributeSet atts) {
     super(context, atts); 
 } 
...