zoukankan      html  css  js  c++  java
  • [FIX BUG]获取theme中自定义textColor时报的错误

    我在Fragment中inflate它都可以,可是一旦使用ListView来inflate就会报错,说找不到我自定义的attr!研究了半天发现是我的inflate的context有问题:

    view = LayoutInflater.from(getActivity().getApplicationContext())
                            .inflate(R.layout.setting_local_book_item, arg2, false);

    发现了什么问题吗?最终发现居然不可以使用AppContext,而是只能使用Activity级别的!请问有人知道为什么吗?

    view = LayoutInflater.from(getActivity())
                            .inflate(R.layout.setting_local_book_item, arg2, false);

    这样就可以了。


    最后附上我的LOG:

    07-13 18:03:50.120: W/System.err(15302): android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.Button
    07-13 18:03:50.130: W/System.err(15302):     at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    07-13 18:03:50.130: W/System.err(15302):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    07-13 18:03:50.140: W/System.err(15302):     at com.turtle.wordlock.SettingLocalBookFragment$MyListviewAdapter.getView(SettingLocalBookFragment.java:104)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.AbsListView.obtainView(AbsListView.java:2038)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.ListView.makeAndAddView(ListView.java:1772)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.ListView.fillDown(ListView.java:672)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.ListView.fillFromTop(ListView.java:732)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.ListView.layoutChildren(ListView.java:1625)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.AbsListView.onLayout(AbsListView.java:1868)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.140: W/System.err(15302):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    07-13 18:03:50.140: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at com.slidingmenu.lib.CustomViewAbove.onLayout(CustomViewAbove.java:476)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.View.layout(View.java:11303)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
    07-13 18:03:50.150: W/System.err(15302):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2445)
    07-13 18:03:50.160: W/System.err(15302):     at android.os.Handler.dispatchMessage(Handler.java:99)
    07-13 18:03:50.160: W/System.err(15302):     at android.os.Looper.loop(Looper.java:137)
    07-13 18:03:50.160: W/System.err(15302):     at android.app.ActivityThread.main(ActivityThread.java:4424)
    07-13 18:03:50.160: W/System.err(15302):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-13 18:03:50.160: W/System.err(15302):     at java.lang.reflect.Method.invoke(Method.java:511)
    07-13 18:03:50.160: W/System.err(15302):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    07-13 18:03:50.160: W/System.err(15302):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    07-13 18:03:50.160: W/System.err(15302):     at dalvik.system.NativeStart.main(Native Method)
    07-13 18:03:50.160: W/System.err(15302): Caused by: java.lang.reflect.InvocationTargetException
    07-13 18:03:50.160: W/System.err(15302):     at java.lang.reflect.Constructor.constructNative(Native Method)
    07-13 18:03:50.160: W/System.err(15302):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    07-13 18:03:50.160: W/System.err(15302):     at android.view.LayoutInflater.createView(LayoutInflater.java:586)
    07-13 18:03:50.160: W/System.err(15302):     ... 54 more
    07-13 18:03:50.160: W/System.err(15302): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f010062 a=-1}
    07-13 18:03:50.170: W/System.err(15302):     at android.content.res.Resources.loadColorStateList(Resources.java:2042)
    07-13 18:03:50.170: W/System.err(15302):     at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
    07-13 18:03:50.170: W/System.err(15302):     at android.widget.TextView.<init>(TextView.java:786)
    07-13 18:03:50.170: W/System.err(15302):     at android.widget.Button.<init>(Button.java:108)
    07-13 18:03:50.170: W/System.err(15302):     at android.widget.Button.<init>(Button.java:104)
    07-13 18:03:50.170: W/System.err(15302):     ... 57 more

  • 相关阅读:
    js代码细嚼慢咽
    HTML知识点记录

    css知识点
    算法第五章作业
    算法第五章上机实践报告
    算法第四章上机实践报告
    算法第四章作业
    算法第三章上机实践报告
    算法第三章作业
  • 原文地址:https://www.cnblogs.com/turtlegood/p/3188261.html
Copyright © 2011-2022 走看看