无法在模拟器上显示AlertDialog

时间:2013-10-12 07:34:32

标签: android android-alertdialog

我在我的应用中使用HoloEveryWhere。我也将这个库用于AlertDialog s。当我在模拟器上运行我的应用程序时,它在Android 2.x和4.x上工作正常但如果我选择Android 3(仅Android 3,即使它在Android 3.1上工作正常),如果应用程序想要显示{ {1}}。我的代码是问题吗?

AlertDialog

更新1: 如果我不使用 android.view.LayoutInflater inflater(android.view.LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View vi = inflater.inflate(com.test.di.xml, null); new AlertDialog.Builder(this).setView(vi) .setPositiveButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { contentValues = new ContentValues(); // tasks } }).setNegativeButton("Cancel", null).setTitle("title") .show(); 库,那么我不会收到这些错误!

更新2: 应用程序在模拟器上运行,Android 3:

HoloeveryWhere

这里是进口商品:

    10-12 15:07:03.594: E/AndroidRuntime(479): FATAL EXCEPTION: main
10-12 15:07:03.594: E/AndroidRuntime(479): java.lang.IllegalStateException: Could not execute method of the activity
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.view.View$1.onClick(View.java:2704)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.view.View.performClick(View.java:3100)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.view.View$PerformClick.run(View.java:11644)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.os.Handler.handleCallback(Handler.java:587)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.os.Looper.loop(Looper.java:126)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.app.ActivityThread.main(ActivityThread.java:3997)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.reflect.Method.invokeNative(Native Method)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.reflect.Method.invoke(Method.java:491)
10-12 15:07:03.594: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-12 15:07:03.594: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-12 15:07:03.594: E/AndroidRuntime(479):  at dalvik.system.NativeStart.main(Native Method)
10-12 15:07:03.594: E/AndroidRuntime(479): Caused by: java.lang.reflect.InvocationTargetException
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.reflect.Method.invokeNative(Native Method)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.reflect.Method.invoke(Method.java:491)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.view.View$1.onClick(View.java:2699)
10-12 15:07:03.594: E/AndroidRuntime(479):  ... 11 more
10-12 15:07:03.594: E/AndroidRuntime(479): Caused by: java.lang.NoClassDefFoundError: android.view.accessibility.AccessibilityNodeInfo
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.Class.getDeclaredMethods(Native Method)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.ClassCache.getDeclaredMethods(ClassCache.java:140)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.Class.getDeclaredMethod(Class.java:725)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:744)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:734)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:734)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:538)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:488)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.app.Dialog.requestDecorView(Dialog.java:155)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.app.Dialog.setContentView(Dialog.java:170)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.app.AlertDialog.installDecorView(AlertDialog.java:405)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.internal.AlertController.installContent(AlertController.java:474)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.app.AlertDialog.onCreate(AlertDialog.java:411)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.app.Dialog.dispatchOnCreate(Dialog.java:335)
10-12 15:07:03.594: E/AndroidRuntime(479):  at android.app.Dialog.show(Dialog.java:248)
10-12 15:07:03.594: E/AndroidRuntime(479):  at org.holoeverywhere.app.AlertDialog$Builder.show(AlertDialog.java:345)
10-12 15:07:03.594: E/AndroidRuntime(479):  at com.test.HomeActivity.delayClicked(HomeActivity.java:353)
10-12 15:07:03.594: E/AndroidRuntime(479):  ... 14 more
10-12 15:07:03.594: E/AndroidRuntime(479): Caused by: java.lang.ClassNotFoundException: android.view.accessibility.AccessibilityNodeInfo in loader dalvik.system.PathClassLoader[/data/app/com.test-1.apk]
10-12 15:07:03.594: E/AndroidRuntime(479):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
10-12 15:07:03.594: E/AndroidRuntime(479):  at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
10-12 15:07:03.594: E/AndroidRuntime(479):  ... 31 more

1 个答案:

答案 0 :(得分:1)

更改此

 android.view.LayoutInflater inflater(android.view.LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View vi = inflater.inflate(com.test.di.xml,
        null);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = inflater.inflate(R.layout.mylayout,
            null);

编辑:

    TextView tv = new TextView(this);
    tv.setText("Holo every where");
    Builder builder=   new org.holoeverywhere.app.AlertDialog.Builder(this);
    builder.setTheme(AlertDialog.THEME_HOLO_LIGHT);
    builder.setView(tv)
    .setPositiveButton("OK", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            // tasks
        }
    }).setNegativeButton("Cancel", null).setTitle("title");
    builder.show();
快照

enter image description here