我得到了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);
首先它用 抛出异常setTextAlignment
,然后我将其删除并用该setBackground
方法再次抛出它。
是什么导致了这个错误?这是否意味着我的应用与 4.1.2 以下的 Android 版本不兼容?创建项目时,我将最小值设置为 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)