NotFoundException in layout editor for Android?

Posted by borg17of20 on Stack Overflow See other posts from Stack Overflow or by borg17of20
Published on 2010-02-27T17:05:02Z Indexed on 2011/01/17 19:53 UTC
Read the original article Hit count: 305

I'm trying to extend a RelativeLayout object and include an embedded SurfaceView object that uses a png file in my /res/drawable folder as its background but I keep getting an error in the XML Layout editor. See the following code:

public class StopMotionRelativeLayout extends RelativeLayout
{
    private Context myContext;
    private SurfaceView surfaceView1;

    private BitmapFactory.Options myBitmapOptions;
    private final android.view.ViewGroup.LayoutParams params = 
        new LayoutParams(LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT);

    public StopMotionRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        myContext = context;
        this.setBackgroundColor(Color.GREEN);

        //init images
        surfaceView1 = new SurfaceView(myContext,attrs);
        surfaceView1.setVisibility(View.INVISIBLE);
        this.addView(surfaceView1, params);

    }

        @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        myBitmapOptions = new Options();
        myBitmapOptions.outWidth = widthMeasureSpec;
        myBitmapOptions.outHeight = heightMeasureSpec;

        surfaceView1.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(this.myContext.getResources(),
                R.drawable.golf1, myBitmapOptions)));
    }
}

I get the following error:

NotFoundException: Could not find drawable resource matching value 0x7F020002 (resolved name: golf1) in current configuration.

I have seen this type of error may times now and it always happens when I try to load something from a resource file via code and not XML. Curiously, this error does not stop me from compiling the app, and the app runs without error in the emulator. I'd like to get back the use of my layout editor though...

Please help.

UPDATE: Here is the layout XML

<?xml version="1.0" encoding="utf-8"?>

<com.games.test.StopMotionRelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">
</com.games.test.StopMotionRelativeLayout>

© Stack Overflow or respective owner

Related posts about java

Related posts about android