why this exception: java.lang.RuntimeException: Error inflating class

I am trying to develop a tiny android app that just opens a browser to a website. I am using mac OS 10.6 and the latest android/eclipse tools. But I keep getting this exception:

11-29 13:03:55.113: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycomp/com.mycomp.pack}: android.view.InflateException: Binary XML file line #7: Error inflating class com.mycomp.MyTextView

Here is my code:

package com.mycomp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;


public class myapp extends Activity {
/** Called when the activity is first created. */`

private MyTextView myview;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);      
    Log.d("onCreate", "onCreate ");   

    myview  = (MyTextView)findViewById(R.id.myview);
    myview.setParent(this);
}




public static   class MyTextView extends TextView {
    private View mLastVisChangedView;
    private int mLastChangedVisibility;
    private Activity parent;

    public void setParent(Activity p){
        parent =p;

    }
    public MyTextView(Context context) {
        super(context);
    }

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

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public View getLastVisChangedView() {
        return mLastVisChangedView;
    }

    public int getLastChangedVisibility() {
        return mLastChangedVisibility;
    }

    @Override
    protected void  onVisibilityChanged(View changedView, int visibility){
        Log.d("onVisibilityChanged", "new vis == " + visibility);
        if (parent !=null && visibility == View.VISIBLE){
            parent.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mysite.com")));
            parent.moveTaskToBack(true);
        }
    }
}

}

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

<com.mycomp.MyTextView
     android:id="@+id/myview"
      android:text="@string/hello"/>

</LinearLayout>

Answers


The type would be com.mycomp.myapp.MyTextView. (Or $ since it's an inner class?)

You may also need to specify the view as follows:

<view class="com.mycomp.myapp$MyEditText" ...

I don't think you need an onFinishInflate in this case.


Need Your Help

Why doesn't with…do statement and rectangle work together flawlessly?

.net field delphi-prism with-statement

Lately, I have been noticing that anytime I use Rectangle variable with With...do statement, it doesn't work at all for some reason.

Deleting some data as a periodic/scheduling job In Java

java spring hibernate jboss scheduler

I am working in Java project with Spring and Hibernate framework. The database used is Oracle and application server is JBoss 4 and OS is Unix.

Programming language where you can refer to a array element by . (dot)

c# arrays

In C# language when you refer to an array element you can write: