0

这是我班级中的 onCreate(...) 方法:

    protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.editor);
            setRequestedOrientation(1);

            v = new SView(this);
            v.setOnTouchListener(this);
            //v.setZOrderOnTop(true);
            //v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
            setContentView(v);

            ImageView back = (ImageView) findViewById(R.id.IVEditor);
            bm = loadPhoto("photo", bm);
            if(bm != null)
            {
                    //This Section is giving me the error

                back.setImageBitmap(bm);

            }
        }

这是错误,当我双击它时,它会将我带到上面的单独部分。我不知道为什么:

11-09 07:42:42.624: E/AndroidRuntime(32472): Caused by: java.lang.NullPointerException
11-09 07:42:42.624: E/AndroidRuntime(32472):    at com.synlight_development.tattoo_it.Editor.onCreate(Editor.java:64)
11-09 07:42:42.624: E/AndroidRuntime(32472):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
11-09 07:42:42.624: E/AndroidRuntime(32472):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
11-09 07:42:42.624: E/AndroidRuntime(32472):    ... 11 more
4

3 回答 3

0
ImageView back = (ImageView) findViewById(R.id.IVEditor);

R.id.IVEditor必须在您设置的布局内声明setContentView

大概R.id.IVEditor是在里面声明的R.layout.editor。切换

 ImageView back = (ImageView) findViewById(R.id.IVEditor);
 bm = loadPhoto("photo", bm);
 if(bm != null) {
     back.setImageBitmap(bm);
 }

  v = new SView(this);
  v.setOnTouchListener(this);
  //v.setZOrderOnTop(true);
 //v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
  setContentView(v);

应该成功。但这一切都取决于在哪里R.id.IVEditor声明;

于 2012-11-09T12:49:53.150 回答
0

你能把你的编辑器布局文件内容粘贴到这里吗?因为那个 editor.xml 布局文件必须有一个 ImageView 作为它的元素,其 id 定义为android:id = "@+id/IVEditor". 然后只有你会得到确切的 ImageView 对象。

于 2012-11-09T13:06:49.543 回答
0

据我了解,您似乎正在R.id.editorSView. 我有一段时间没有接触 Android,所以不确定是什么SView。但是,我首先会认为它会用setContentView(R.id.Editor)不包含带有 id 的布局元素的自定义视图/布局/whater替换您以前的内容R.layout.IVEditor

所以,是的,您尝试将图像添加到当前布局中不存在的内容中。(setContentView(v)正在删除R.id.editor布局并放入不包含R.layout.IVEditor.

于 2012-11-09T13:15:03.710 回答