In your board.xml I think there is an error, but I might be wrong as I
am new, but still..

when you define LinearLayout you end it with "/>" insted ending it
with just">" without slash since it is open and you are ending it with
"</LinearLayout>" a few lines down. Maybe that is the problem?

On Feb 21, 1:31 pm, Alok Nath <nath.a...@gmail.com> wrote:
> Hi Gurus!
>   I am trying to use a custom view for my application.
>   When I run the program it gives me an error, something like this
>
>   java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.game.subgame/com.game.subgame.BoardActivity}:
>   android.view.InflateException: Binary XML file line #6: Error inflating
> class com.game.brainer.Board
>
>   Not sure what I am missing here.
>
>   What I want to do is - use the Board view class in my BoardActivity
> Activity.
>
>   Can someone please help me out here ?
>
> Thanks,
> Alok.
>
>  //-- BoardActivity.java
> public class BoardActivity extends Activity{
>
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>
>         Board boardView = new Board(this);
>         //setContentView(boardView);   // This works fine but i want to use
> the board.xml
>         setContentView(R.layout.board);
>  }
>
> }
>
> //-- Board.java ---
>
>  public class Board extends View {
>     int _height;
>     int _width;
>
>     Bitmap _bitmap;
>     Canvas _canvas;
>     Paint _paint;
>
>     public Board(Context context) {
>         super(context);
>         // TODO Auto-generated constructor stub
>         _paint = new Paint();
>         _paint.setColor(Color.RED);
>         _paint.setStyle(Paint.Style.STROKE);
>         _paint.setStrokeWidth(10);
>     }
>
>     public Board(Context context, AttributeSet atts) {
>         super(context, atts);
>
>         // Is there any problem here ??
>
>       }
>
>     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
>         //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
>         _height = View.MeasureSpec.getSize(heightMeasureSpec) ;
>         _width = View.MeasureSpec.getSize(widthMeasureSpec) ;
>
>         setMeasuredDimension(_width, _height);
>         _bitmap = Bitmap.createBitmap(_width, _height,
> Bitmap.Config.ARGB_8888);
>         _canvas = new Canvas(_bitmap);
>     }
>
>     @Override
>     protected void onDraw(Canvas canvas) {
>         canvas.drawBitmap(_bitmap, 0, 0, _paint);
>
>         //button = (Button)findViewById(R.id.matchImage);
>
>     }
>
> }
>
> ---  board.xml ---------
>
> <LinearLayout
>   android:layout_width="fill_parent"
>   android:layout_height="fill_parent">
>   <com.game.brainer.Board android:id="@+id/board"
>         android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>         android:layout_weight="1"
>   />
>    <Button android:textSize="50sp"
>           android:layout_height="wrap_content"
>           android:text="Button" android:id="@+id/matchImage"
>          android:layout_width="wrap_content"/>
> </LinearLayout>
>
> Error Log :
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418): java.lang.RuntimeException:
> Unable to start activity
> ComponentInfo{com.game.subgame/com.game.subgame.BoardActivity}:
> android.view.InflateException: Binary XML file line #6: Error inflating
> class com.game.brainer.Board
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread.access$2200(ActivityThread.java:119)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.os.Looper.loop(Looper.java:123)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread.main(ActivityThread.java:4363)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> java.lang.reflect.Method.invoke(Method.java:521)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 
> 860)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> dalvik.system.NativeStart.main(Native Method)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418): Caused by:
> android.view.InflateException: Binary XML file line #6: Error inflating
> class com.game.brainer.Board
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.view.LayoutInflater.inflate(LayoutInflater.java:407)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.view.LayoutInflater.inflate(LayoutInflater.java:320)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.view.LayoutInflater.inflate(LayoutInflater.java:276)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.jav 
> a:198)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.Activity.setContentView(Activity.java:1622)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> com.game.subgame.BoardActivity.onCreate(BoardActivity.java:15)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
> 02-21 11:13:42.392: ERROR/AndroidRuntime(418):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to