0

我在我的项目中同时使用 ActionBarSherlock 和 HoloEverywhere 作为库,突然 HoloEverywhere 开始搞砸了。

我做了一个这样的 AlertDialog:

AlertDialog.Builder alert = new AlertDialog.Builder(DomaCareDetailViewActivity.this)
    .setTitle(R.string.edit_service)
    .setItems(R.array.edit_service_array, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
                //tested and working code
            });
alert.create();
alert.show();

但是“创建”行抛出异常:

03-21 17:05:35.167: E/AndroidRuntime(25499): FATAL EXCEPTION: main
03-21 17:05:35.167: E/AndroidRuntime(25499): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.LayoutInflater.tryCreateView(LayoutInflater.java:359)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:308)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:287)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:272)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:267)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.internal.AlertController$AlertParams.createListView(AlertController.java:143)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.internal.AlertController$AlertParams.apply(AlertController.java:129)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.app.AlertDialog$Builder.create(AlertDialog.java:60)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at com.invian.domacare.task.DomaCareDetailViewActivity$20.onClick(DomaCareDetailViewActivity.java:1004)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.View.performClick(View.java:4084)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.View$PerformClick.run(View.java:16966)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.os.Handler.handleCallback(Handler.java:615)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.os.Looper.loop(Looper.java:137)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.app.ActivityThread.main(ActivityThread.java:4931)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at java.lang.reflect.Method.invokeNative(Native Method)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at java.lang.reflect.Method.invoke(Method.java:511)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at dalvik.system.NativeStart.main(Native Method)
03-21 17:05:35.167: E/AndroidRuntime(25499): Caused by: java.lang.reflect.InvocationTargetException
03-21 17:05:35.167: E/AndroidRuntime(25499):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-21 17:05:35.167: E/AndroidRuntime(25499):    ... 24 more
03-21 17:05:35.167: E/AndroidRuntime(25499): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01007a a=-1}
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.content.res.Resources.loadDrawable(Resources.java:1921)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at android.widget.ListView.<init>(ListView.java:153)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.widget.ListView.<init>(ListView.java:205)
03-21 17:05:35.167: E/AndroidRuntime(25499):    at org.holoeverywhere.widget.ListView.<init>(ListView.java:200)
03-21 17:05:35.167: E/AndroidRuntime(25499):    ... 27 more

我在 HoloEverywhere 的 com.holoeverywhere.internal.AlertController 中找到了源代码,第 143 行有问题:

final ListView listView = (ListView) mInflater
    .inflate(dialog.mListLayout, null);

检查 mListLayout 的初始化将我带到第 383 行:

mListLayout = a.getResourceId(R.styleable.AlertDialog_listLayout,
    R.layout.select_dialog_holo);

这是据我所知。我找不到“R.styleable.AlertDialog”,但由于 AlertDialog.create() 在我的项目中引发了异常,我确信这就是问题所在。然而,select_dialog_holo.xml 文件确实有自己的错误:

Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.

Failed to convert ?listDividerAlertDialog into a drawable
Couldn't find theme resource listDividerAlertDialog for the current theme

有人对如何解决这个问题有任何想法吗?

编辑:浏览 HoloEverywhere 布局文件夹,我注意到有大量此类错误。例如,simple_list_item_1 给了我几个“找不到资源”错误以及一些“属性 paddingLeft 中的 listPreferredPaddingLeft/Right/etc 不是有效格式”错误。

4

0 回答 0