3

I'm new to Android and i'm trying to inflate a layout in xml but i get a RuntimeException. I have cut out almost everything except for my activity class and the class extending SurfaceView. Can anyone tell me what i'm doing wrong?

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"    
android:layout_height="match_parent">    
<com.hj.Panel    
android:id="@+id/SurfaceView01"      
android:layout_width="match_parent"      
android:layout_height="match_parent"/>    
</FrameLayout>

Rita.java:

package com.hj;

import android.app.Activity;
import android.os.Bundle;

public class Rita extends Activity {
/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }
}

Panel.java:

package com.hj;

import android.content.Context; 
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.SurfaceView;

class Panel extends SurfaceView {    
  private Paint mPaint;

  public Panel(Context context) {
    super(context); 
  }  
  @Override
  public void onDraw(Canvas canvas) {          
    mPaint = new Paint();  
    canvas.drawRect(0, 0, 322, 644, mPaint);
  }          
} 
Henrik
  • 31
  • 1
  • 2

2 Answers2

1

In order to make your code run I had to do the following:

1) change "match_parent" to "fill_parent"

2) add constructor

  public Panel(Context context, AttributeSet atts) {
    super(context, atts); 
  } 

You may want to try that

Asahi
  • 13,378
  • 12
  • 67
  • 87
0

You should always post a stack trace when you report an exception. (Run adb logcat on the command line, or view the logcat window in eclipse).

Without that, my best guess is that it should be fill_parent, not match_parent.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82