今天用一个安卓4.0.4版本的手机测试手上的项目,发现logcat弹出这样一个提示“java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground”,然后这个页面因为没有做异常捕获处理,所以直接导致系统崩溃了.检查后发现里面设置背景用的是setBackground()方法,而该方法是API16才开始有的.遇到这样的情况,将这个方法更改为setBackgroundDrawable()就可以了.…
安卓的背景色设置需要根据SDK的版本来分情况考虑: if (Build.VERSION.SDK_INT >= 16) { textView.setBackground(null); } else { textView.setBackgroundDrawable(null); }…
最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView 原因: 可能是没有在适配器参数内加入TextView的id. 解决方案: 将原来的适配器参数代码 mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.list…
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams FrameLayout的父控件是一个LinearLayout控件,问题出在,LinearLayout为子控件分配空间的时候,获取FrameLayout的LayoutParams的必须为LinearLayout.LayoutParams,而…
1.在xml布局文件如下所示: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/darker_gray" android:paddingBottom="5dp" android:paddingTop="5dp&qu…
RelativeLayout title_bg = (RelativeLayout)FTU_Bluetooth.this.findViewById(R.id.titlebar); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0x55); title_bg.setLayoutParams(params); 如果用RelativeLayout.LayoutPara…
int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { setBackgroundDrawable(); } else { setBackground(); }…
今天在开发的时候,这个代码在源码中是可以看到的,但是在android 4.3手机上面会报错,具体错误信息和代码如下: setBackgroundDrawable(context.getDrawable(R.drawable.coach_popou_window)):会报这个错误java.lang.NoSuchMethodError:android.content.Context.getDrawable查阅资料可以得到这个解释: 改成这样即可 setBackgroundDrawable(Conte…
1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor或者 java.lang.NoSuchMethodError:android.content.Context.getDrawable/geColor 原因:Context类的getDrawable(res)/geColor(res)方法和Resources的getDrawable(res,theme)/getColor(res.them…
Caused by: Java.lang.ClassCastException: Android.widget.TextView cannot be cast to android.widget.EditText 该种报错信息,检查代码确定无误后,若还是出现这种错误,则可通过以下这个办法进行解决: 点中该项目-->点击Project-->clean   清理下再重新运行该项目…