2014-04-01 125 views
0

我有两个活动;一个拍摄照片,另一个显示照片并在相对布局中放置标记。我通过一个Intent将第一个活动拍摄的图片发送给第二个,并将其解码为如下的Bitmap,但我仍然收到NullPointerException的任何帮助?: Edit1:当我使用png资源并将其添加到XML中时布局一切似乎是确定的。添加一张照相机拍摄的照片作为我的相对布局

Bitmap b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0, getIntent().getByteArrayExtra("byteArray").length); 

Resources res = getResources(); 

Drawable bd = new BitmapDrawable(res,b); 

RelativeLayout rl = (RelativeLayout) findViewById(R.id.touchanddrag); 
rl.setBackground(bd) 
setContentView(R.layout.touchanddrag); 
+0

你可以张贴logcat的? – SMR

回答

1
setContentView(R.layout.touchanddrag); should be right after onCreate() statement. 

您获得空指针这里,rl.setBackground(bd)作为布局尚未初始化,您试图访问其组件(你的RelativeLayout)。

因此,在super.onCreate()语句后移动这个setContentView(R.layout.touchanddrag);并检查它是如何进行的。

+0

感谢您的提示,现在我没有收到任何错误,但背景是白色的!任何帮助? – Yourange

+0

尝试setBackgroudDrawable(),但是两者没有太大区别(尝试一次)。将代码发布到您通过意图额外的地方。 –

+0

我测试过这个和同样的东西,, – Yourange

0

原来有低于我的长码第二的setContentView,这是我的问题...感谢您的帮助,并希望这种帮助别人

相关问题