程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-Android下面代碼運行時候報錯,仔細核對了控件名,沒有問題,求各位大神幫忙看看

android-Android下面代碼運行時候報錯,仔細核對了控件名,沒有問題,求各位大神幫忙看看

編輯:編程綜合問答
Android下面代碼運行時候報錯,仔細核對了控件名,沒有問題,求各位大神幫忙看看

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

最佳回答:


控件android
button_user_alert.setOnClickListener(new OnClickListener() {
View view = View.inflate(DialogComponentTest.this, R.layout.user_dialog, null);**
final EditText userName = (EditText) view.findViewById(R.id.edit_text_name);
final EditText passWord = (EditText) view.findViewById(R.id.edit_text_password);**

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved