views:

70

answers:

1

I am trying to refer to a custom View in the helloWorld XML layout but I get the following exception: Error inflating class acme.my.MyTextView.

However, I am able to instantiate the view and add it to the main content view manually. The custom View is built from it's own XML layout. How do I get this to work?

public class MyTextView extends LinearLayout {  

 MyTextView(Context context){
  super(context);

  LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  layoutInflater.inflate(R.layout.my_text_view,this);
 }

 MyTextView(Context context, AttributeSet attrs){
  super(context, attrs);

  LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  layoutInflater.inflate(R.layout.my_text_view,this);
 }
}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />

  <view class = "acme.my.MyTextView"
 android:id="@+id/myView" 
 android:orientation="vertical"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"           
 />
A: 

The constructors aren't public. :(