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

When to use events over commands in WPF?

wpf mvvm mvvm-light routed-commands eventtocommand

Hi i have recently looked into WPF and started learning about Events and Commands. I typically use Commands on Button clicks which causes a method to Run in my "view model".

Make my awk shell script more efficient (parsing python)

python bash shell awk

I was recently tasked with auditing all of the python modules my team uses across our entire production code repository.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.