button_user_alert.setOnClickListener(new OnClickListener() {
View view = View.inflate(DialogComponentTest.this, R.layout.user_dialog, null);
final EditText userName = (EditText) findViewById(R.id.edit_text_name);
final EditText passWord = (EditText) findViewById(R.id.edit_text_password);
@Override
public void onClick(View v) {
new AlertDialog.Builder(DialogComponentTest.this)
.setView(view)
.setPositiveButton("取消", null)
.setNegativeButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//这里出现nullPointerException,不知道该怎么处理,找不出问题所在
String strUserName = userName.getText().toString();
String strPassWord = passWord.getText().toString();
Toast.makeText(DialogComponentTest.this,strUserName +" : "+strPassWord, 0).show();
}
})
.show();
}
});
错误信息如下:
01-13 13:41:16.472: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
01-13 13:41:20.792: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
01-13 13:41:27.512: E/AndroidRuntime(1878): FATAL EXCEPTION: main
01-13 13:41:27.512: E/AndroidRuntime(1878): java.lang.NullPointerException
01-13 13:41:27.512: E/AndroidRuntime(1878): at com.example.uitest.DialogComponentTest$3$1.onClick(DialogComponentTest.java:97)
01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
01-13 13:41:27.512: E/AndroidRuntime(1878): at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 13:41:27.512: E/AndroidRuntime(1878): at android.os.Looper.loop(Looper.java:137)
01-13 13:41:27.512: E/AndroidRuntime(1878): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-13 13:41:27.512: E/AndroidRuntime(1878): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 13:41:27.512: E/AndroidRuntime(1878): at java.lang.reflect.Method.invoke(Method.java:511)
01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-13 13:41:27.512: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-13 13:41:27.512: E/AndroidRuntime(1878): at dalvik.system.NativeStart.main(Native Method)
01-13 13:41:27.572: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
01-13 13:41:29.352: E/Trace(1899): error opening trace file: No such file or directory (2)
01-13 13:41:29.383: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
01-13 13:41:29.393: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
如果换手机用安卓试一下程序,结果出现了一大片看不懂的报错。 看下有无出现关键报错信息: 1.Unknown failure (at android.os.Binder.execTransact(Binder.java:565)) 2.Error while Installing APKs 3.Session 'app': Error Installing APKs 4.Failed to finalize session : INSTALL_FAILED_INTERNAL_ERROR 根据以上信息百度并按照各路大神的解决办法尝试一遍,解决办法如下: 1.重新编译 2.手机拔掉,重新插 3.改变Android studio的设置,去掉第一个复选框的勾,但是这个方法对于我来说还是没有用,照样报错 首先,在虚拟机上运行了一遍程序,没有报错 其次,用以前的手机运行,也没有报错,说明是现在的手机有什么问题 然后,重启了一遍手机,进入开发者模式 这时候如果发现虽然USB调试都是打开状态 但是开发者模式处于关闭状态!!
“答案来源于网络,供您参考” 希望以上信息可以帮到您!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。