Java Android布局编辑器中的NotFoundException?

Java Android布局编辑器中的NotFoundException?,java,android,eclipse,android-layout,Java,Android,Eclipse,Android Layout,我试图扩展RelativeLayout对象并包含一个嵌入的SurfaceView对象,该对象使用my/res/drawable文件夹中的png文件作为背景,但在XML布局编辑器中不断出现错误。请参阅以下代码: public class StopMotionRelativeLayout extends RelativeLayout { private Context myContext; private SurfaceView surfaceView1; private

我试图扩展RelativeLayout对象并包含一个嵌入的SurfaceView对象,该对象使用my/res/drawable文件夹中的png文件作为背景,但在XML布局编辑器中不断出现错误。请参阅以下代码:

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)));
    }
}
我得到以下错误:

NotFoundException:找不到 可提取资源匹配值 中的0x7F020002(解析名称:golf1) 当前配置

我已经多次看到这种类型的错误,当我试图通过代码而不是XML从资源文件加载某些内容时,这种错误总是会发生。奇怪的是,这个错误并没有阻止我编译应用程序,而且应用程序在模拟器中运行时没有错误。不过我想重新使用我的布局编辑器

请帮忙

更新:这是布局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>

如果您在XML中为android:background指定一个值,然后在代码中重写它,我想知道它是否有效


作为一种解决方法,您还可以尝试调用isInEditMode()函数,而不在编辑模式下设置背景。

为了完整起见,您介意发布布局XML吗?您的golf1.png是否位于/res/drawable-[h | m | l]dpi文件夹中,该文件夹与您的模拟器/设备的配置相匹配?在使用解码器时,将资源放在正确的文件夹中可能至关重要,因为您要处理它,而不是让默认的缩放或裁剪发生。