[FIX BUG]获取theme中自定义textColor时报的错误_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > [FIX BUG]获取theme中自定义textColor时报的错误

[FIX BUG]获取theme中自定义textColor时报的错误

 2013/7/15 22:48:21  turtlegood  博客园  我要评论(0)
  • 摘要:我在Fragment中inflate它都可以,可是一旦使用ListView来inflate就会报错,说找不到我自定义的attr!研究了半天发现是我的inflate的context有问题:view=LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.setting_local_book_item,arg2,false);发现了什么问题吗?最终发现居然不可以使用AppContext
  • 标签:自定义 错误

我在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

发表评论
用户名: 匿名