java - com.google.zxing.client.android.result return a Null pointer exception -
i trying develop simple app read qr code zxing , redirect corresponding link. mainactivity class, methods on create , onactivityresult, when scan qr code app crashes....and dunno why can me? post mainactivity class, if can help...
thanks all
fabrizio
-------- mainactivity------------
public class mainactivity extends activity { // static final string action_scan = "com.google.zxing.client.android.scan"; private button button; private webview webview; @override protected void oncreate(bundle savedinstancestate) { final context context = this; super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.go_direct); button.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { intent intent = new intent(context, webviewactivity.class); startactivity(intent); } }); } public void scannow(view view) { intent intent = new intent("com.google.zxing.client.android.scan"); // intent.setpackage("com.google.zxing.client.android"); intent.putextra("com.google.zxing.client.android.scan.scan_mode", "qr_code_mode"); startactivityforresult(intent, 0); } @suppresslint("setjavascriptenabled") public void onactivityresult(int requestcode, int resultcode, intent intent) { if (requestcode == 0) { if (resultcode == result_ok) { string contents = intent.getstringextra("scan_result"); log.i("intent", intent.tostring()); log.i("scan result", intent.getstringextra("scan_result")); string format = intent.getstringextra("scan_result_format"); log.i("xzing", "contents: " + contents + " format: " + format); // handle // successful // scan setcontentview( r.layout.web_view); webview = (webview) findviewbyid(r.id.webview1); webview.getsettings().setjavascriptenabled(true); webview.setwebviewclient(new mywebviewclient()); webview.loadurl(contents); } else if (resultcode == result_canceled) { // handle cancel log.i("xzing", "cancelled"); } } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item);}}
Comments
Post a Comment