use*_*221 4 android view nosuchmethoderror textview
我正在接受一个NoSuchMethodError我所做的课程TextView.我唯一做的就是添加一些变量并添加onLongClickListener.没有更多的修改.
当我在我的Android手机4.1.2中使用我的应用程序时,一切正常.但是在我朋友的手机4.0.3中,它会抛出这个NoSuchMethodError.
这是我创建扩展Textview的类时的代码:
descrip=new TextViewList(context, admin, this);
descrip.setPadding(0, 15, 0, 15);
descrip.setGravity(Gravity.CENTER);
descrip.setTextAlignment(Gravity.CENTER);
descrip.setText(c.getString(c.getColumnIndex("Descripcion")));
descrip.setTag(c.getString(c.getColumnIndex("ID")));
descrip.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
descrip.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
descrip.setBackground(img);
layDescripcion.addView(descrip);
Run Code Online (Sandbox Code Playgroud)
首先它抛出了异常setTextAlignment,然后我将其删除并再次使用该setBackground方法抛出它.
导致此错误的原因是什么?这是否意味着我的应用与4.1.2以下的Android版本不兼容?我在创建项目时将minimun设置为2.2.我正在使用android.support.v4库请求它们.
这是LogCat:
07-09 21:45:26.715: E/AndroidRuntime(13481): FATAL EXCEPTION: main
07-09 21:45:26.715: E/AndroidRuntime(13481): java.lang.NoSuchMethodError: modelo.TextViewList.setBackground
07-09 21:45:26.715: E/AndroidRuntime(13481): at modelo.ListaTextViewList.mostrarGastos(ListaTextViewList.java:92)
07-09 21:45:26.715: E/AndroidRuntime(13481): at controlador.AdminUI.establecerListaGastoVar(AdminUI.java:138)
07-09 21:45:26.715: E/AndroidRuntime(13481): at com.ConApps.walletsaver.GastosVariables.onCreate(GastosVariables.java:23)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.Activity.performCreate(Activity.java:4465)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.ActivityThread.access$600(ActivityThread.java:127)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.os.Looper.loop(Looper.java:137)
07-09 21:45:26.715: E/AndroidRuntime(13481): at android.app.ActivityThread.main(ActivityThread.java:4507)
07-09 21:45:26.715: E/AndroidRuntime(13481): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 21:45:26.715: E/AndroidRuntime(13481): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 21:45:26.715: E/AndroidRuntime(13481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-09 21:45:26.715: E/AndroidRuntime(13481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-09 21:45:26.715: E/AndroidRuntime(13481): at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
Unk*_*own 11
setBackground()仅在16 api.请setBackgroundDrawable()改用.
什么所有电话少于16 api,他们会支持 setBackgroundDrawable()
这是此问题的解决方法:
Drawable d = this.res.getDrawable(R.drawable.metro_circle);
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN ) {
metroIconTextView.setBackground(d);
}
else {
metroIconTextView.setBackgroundDrawable(d);
}
Run Code Online (Sandbox Code Playgroud)