0

I have a custom view in src > myproject.test > HomeView

In my main layout xml I have the following:

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

In the HomeActivity I have a call like this in the onCreate method.

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

The app force closed when the setContentView method is called. It seems that my main xml is not correct.

Any ideas?

skyfoot
  • 20,629
  • 8
  • 49
  • 71

3 Answers3

2

Do you mean its not getting to the

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

and crashing on the line before it?

Check if your constructor is

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

and not

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

you need the AttributeSet

GaryD
  • 128
  • 1
  • 6
0

Check constructors that your HomeView implements:

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

None of my layouts have @+id. Maybe you should set the view to home_root. Check with you R.java for the name of the layout, or try

setContentView(R.layout.home_root);
frayser
  • 1,754
  • 10
  • 17