Unable to start activity ComponentInfo XXX java.lang.IllegalArgumentException: Found empty contents

今天写程序时碰到的问题,在检查AndroidManifest.xml和该Activity的Layout配置文件之后依然找不到问题所在

04-14 13:13:08.200: E/AndroidRuntime(17215): FATAL EXCEPTION: main
04-14 13:13:08.200: E/AndroidRuntime(17215): Process: com.example.four.two.one, PID: 17215
04-14 13:13:08.200: E/AndroidRuntime(17215): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.four.two.one/com.example.four.two.one.QrCodeActivity}: java.lang.IllegalArgumentException: Found empty contents
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2747)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread.access$900(ActivityThread.java:187)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1585)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.os.Handler.dispatchMessage(Handler.java:111)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.os.Looper.loop(Looper.java:194)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread.main(ActivityThread.java:5871)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at java.lang.reflect.Method.invoke(Native Method)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at java.lang.reflect.Method.invoke(Method.java:372)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
04-14 13:13:08.200: E/AndroidRuntime(17215): Caused by: java.lang.IllegalArgumentException: Found empty contents
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.google.zxing.qrcode.QRCodeWriter.encode(QRCodeWriter.java:55)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.google.zxing.MultiFormatWriter.encode(MultiFormatWriter.java:94)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.google.zxing.MultiFormatWriter.encode(MultiFormatWriter.java:47)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.zxing.encoding.EncodingHandler.createQRCode(EncodingHandler.java:22)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at com.example.four.two.one.QrCodeActivity.onCreate(QrCodeActivity.java:41)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.Activity.performCreate(Activity.java:6127)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
04-14 13:13:08.200: E/AndroidRuntime(17215): 	... 10 more



反复检查后发现错误出现在在下面的这个程序段上

	if(str==""){
			qrcodetext.setText("暂时还没有配置钥匙!");
			setResult(RESULT_NOT_OK);
		//	finish();
		}else{
			try {
				Bitmap qrCode = EncodingHandler.createQRCode(str, 600);
				qrimage.setImageBitmap(qrCode);
			} catch (WriterException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

当字符串str不为空时程序正常运行,所以错误可能在if的判断上


尝试修改代码后,运行正常.


if(str.isEmpty()){
			qrcodetext.setText("暂时还没有配置钥匙!");
			setResult(RESULT_NOT_OK);
		//	finish();
		}else{
			try {
				Bitmap qrCode = EncodingHandler.createQRCode(str, 600);
				qrimage.setImageBitmap(qrCode);
			} catch (WriterException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}


你可能感兴趣的:(Android学习)