我试图通过意图打开相机,并将生成的图像存储为位图。然后,在Google地图中点击标记时,我想将此位图传递到另一个布局,该布局将用于填充主要活动布局中的弹出窗口。
然而,我收到错误: " java.lang.NullPointerException:尝试调用虚方法' void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)'在null对象引用"
以下是我的部分代码:
MainActivity:
@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>
答案 0 :(得分:0)
你的意思是(错过了容器?):
List<String> stores = new List<String>();
stores.Add("s27");
stores.Add("s3");
stores.Add("s5");
stores.Add("s1");
var sorted = stores.OrderBy(s => int.Parse(s.Substring(1)));