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);
  }          
} 
1
  • 1
    can you post call stack? Commented Oct 2, 2010 at 19:28

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

'match_parent' doesn't seem to be the problem. This is the stack trace:
'match_parent' doesn't seem to be the problem. This is the stack trace:
'match_parent' doesn't seem to be the problem. This is the stack trace:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.