I tried to create an application with a custom view, and I continued to get the "error blowing class". I must be missing some basics when it comes to custom views, but I'm not sure what. Here is a very simple program with a user view, what else is needed to make it work?
(Notes: For this question, I placed the SurfaceView class inside the Activity class. This situation is not in a larger application. I do not show the AndroidManifest.xml file here, but this is exactly what the wizard created in eclipse.)
Here is java:
package com.mypackage; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.AttributeSet; import android.util.Log; import android.view.SurfaceView; public class SimpleCustomViewActivity extends Activity { class TheView extends SurfaceView{ private static final String TAG = "TheView"; public TheView(Context context, AttributeSet attrs) { super(context, attrs); Log.i(TAG,"TheView(" + context + "," + attrs + ")"); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_layout); TheView v = (TheView) findViewById(R.id.myview); } }
Here is the res / layout / simple_layout.xml file:
<?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" > <com.mypackage.SimpleCustomView.TheView android:id="@+id/myview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
source share