【发布时间】:2016-04-18 22:36:48
【问题描述】:
我正在尝试通过一个意图打开我的相机,并将生成的图像存储为位图。然后,单击 Google 地图中的标记后,我想将此位图传递到另一个布局中,该布局将用于在主活动布局中填充弹出窗口。
但是,我收到错误消息: “java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)'”
以下是我的部分代码:
主活动:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the action was to capture a picture, then store all relevant data in the database
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Picture Received"/*data.getData().toString()*/, Toast.LENGTH_SHORT).show();
Bundle extras = data.getExtras();
imageBitmap = (Bitmap) extras.get("data");
//imageView.setImageBitmap(imageBitmap);
}
}
}
@Override
public boolean onMarkerClick(Marker marker) {
layoutInflator = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup container = (ViewGroup) layoutInflator.inflate(R.layout.imagecontainer, null);
ImageView image = (ImageView) findViewById(R.id.imageView);
image.setImageBitmap(imageBitmap);
popUpWindow = new PopupWindow(container, 800, 1220, true);
popUpWindow.setBackgroundDrawable(new BitmapDrawable());
popUpWindow.setOutsideTouchable(true);
popUpWindow.showAtLocation(relativeLayout, Gravity.CENTER, Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL);
return false;
}
imagecontainer.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:id="@+id/imageContainer">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_gravity="top|center_horizontal" />
</LinearLayout>
【问题讨论】:
标签: android bitmap popup imageview