我有一个弹出窗口,我想显示一个图像和两个按钮。确实出现了按钮,但是当我尝试使用它时,ImageView会抛出nullpointer异常。下面是我显示PopUpWindow的代码片段:
private void initiatePopupWindow() {
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) RestPageActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.popup_details,
(ViewGroup) findViewById(R.id.popup_element));
// create a 300px width and 470px height PopupWindow
System.out.println("SELECTED INDEX" + selectedIndex + "***" + IDs.size());
System.out.println("ITEM ID:" + IDs.get(selectedIndex) + "--------------");
ImageView iv = (ImageView) findViewById(R.id.ivItem);
if (StaticParameters.getCompleteData().getMenusHash().containsKey(IDs.get(selectedIndex))) {
Menu m = StaticParameters.getCompleteData().getMenusHash().get(IDs.get(selectedIndex));
byte[] imgBytes = FileHandler.readFile2(this, "items", m.getActiveImage());
System.out.println("///////////////77" + imgBytes.length + "//" + m.getActiveImage());
if (imgBytes != null && iv != null) {
Bitmap b = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
iv.setImageBitmap(b);
Matrix mMatrix = new Matrix();
mMatrix.setRectToRect(new RectF(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight()), new RectF(0, 0, 100, 100), Matrix.ScaleToFit.CENTER);
} else
System.out.println("else geldi");
} else if (StaticParameters.getCompleteData().getProductsHash().containsKey(IDs.get(selectedIndex))) {
Product m = StaticParameters.getCompleteData().getProductsHash().get(IDs.get(selectedIndex));
byte[] imgBytes = FileHandler.readFile2(this, "items", m.getActiveImage());
System.out.println("///////////////77" + imgBytes.length + "//" + m.getActiveImage());
if (imgBytes != null && iv != null) {
Bitmap b = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
iv.setImageBitmap(b);
Matrix mMatrix = new Matrix();
mMatrix.setRectToRect(new RectF(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight()), new RectF(0, 0, 100, 100), Matrix.ScaleToFit.CENTER);
} else
System.out.println("else geldi");
}
pw = new PopupWindow(layout, 300, 470, true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
//mResultText = (TextView) layout.findViewById(R.id.server_status_text);
Button cancelButton = (Button) layout.findViewById(R.id.cancelButton);
//makeBlack(cancelButton);
cancelButton.setOnClickListener(cancel_button_click_listener);
Button approveButton = (Button) layout.findViewById(R.id.completeButton);
//makeBlack(cancelButton);
approveButton.setOnClickListener(approve_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
如果您的活动中已宣布属性
private ImageView iv;
你必须改变:
ImageView iv = (ImageView) findViewById(R.id.ivItem);
通过
iv = (ImageView) findViewById(R.id.ivItem);
你得到这个nullPointer异常,因为你在本地声明它是我的问题是什么
答案 1 :(得分:0)
更改此行
<input.*?\s*?value='([^']*)
到
await (from t in Users
from c in t.Claims
where c.ClaimType == "CompanyId" && c.ClaimValue == Id
select t).Execute();