0
경고 대화 상자에서 비트 맵을 설정하는 데 문제가 있습니다. 나는 다른 클래스의 바코드를 만들었고 바코드를 대화 상자에 표시하려고합니다. 오류가 계속 표시됩니다. 로그에서 바코드가 성공적으로 생성됩니다. 문제는 계속 qrCodeImageView.setImageBitmap(bitmap);
행을 가리키고 있습니다. 도와주세요.비트 맵이 대화 상자에 표시되지 않습니다
이것은 활동의 메소드입니다.
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at newgbacard.gbacard.com.gbacard.activities.ContactDetailActivity$10.run(ContactDetailActivity.java:336)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.app.Activity.runOnUiThread(Activity.java:5575)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at newgbacard.gbacard.com.gbacard.activities.ContactDetailActivity.showQRCode(ContactDetailActivity.java:316)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at newgbacard.gbacard.com.gbacard.activities.ContactDetailActivity$5.onClick(ContactDetailActivity.java:168)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.view.View.performClick(View.java:5184)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.view.View$PerformClick.run(View.java:20910)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.os.Looper.loop(Looper.java:145)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5942)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at java.lang.reflect.Method.invoke(Native Method)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
10-22 08:51:36.491 10948-10948/newgbacard.gbacard.com.gbacard W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
이 제발 도와주세요 :
public void showQRCode(final Bundle bundle){
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
barcodeUtil = new BarcodeUtil();
Bitmap bitmap = barcodeUtil.createQRCcode(ContactDetailActivity.this, bundle);
AlertDialog.Builder builder = new AlertDialog.Builder(ContactDetailActivity.this);
Log.i(Constants.TAG_GBACARD, "Bmp in Dialog: " + bitmap);
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.custom_dialog, null);
builder.setView(dialogLayout);
final ImageView qrCodeImageView = (ImageView) findViewById(R.id.qrCode);
qrCodeImageView.setImageBitmap(bitmap);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog b = builder.create();
b.show();
} catch (Exception e){
e.printStackTrace();
}
}
});
}
이
이 오류 인 바코드를public Bitmap createQRCcode(final Context context, final Bundle bundle) {
Bitmap bitmap = null;
try {
//Find screen size
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point point = new Point();
display.getSize(point);
int width = point.x;
int height = point.y;
int smallerDimension = width < height ? width : height;
smallerDimension = smallerDimension * 3/4;
//Encode with a QR Code image
qrCodeEncoder = new QRCodeEncoder(null,
bundle,
Contents.Type.CONTACT,
BarcodeFormat.QR_CODE.toString(),
smallerDimension);
bitmap = qrCodeEncoder.encodeAsBitmap();
Log.i(Constants.TAG_GBACARD, "QR Encoded");
Log.i(Constants.TAG_GBACARD, "Bitmap: " + bitmap);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
를 생성하는 방법이다. 감사합니다
덕분에이
를 교체하십시오 –