android - 使用 TextView 方法获取 NoSuchMethodError

标签 android view textview nosuchmethoderror

我收到一个 NoSuchMethodError,其中包含我创建的扩展 TextView 的类。我唯一做的就是添加一些变量并添加 onLongClickListener。没有更多的修改。

当我在我的 Android 手机 4.1.2 中使用我的应用程序时一切正常 但是在我 friend 的 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 方法再次抛出它。

是什么导致了这个错误?这是否意味着我的应用与 Android 不兼容 低于 4.1.2 的版本?我在创建项目时将最小值设置为 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)

最佳答案

setBackground() 仅在 16 api 中引入。请改用 setBackgroundDrawable()

所有少于16个api的手机,他们都支持setBackgroundDrawable()

关于android - 使用 TextView 方法获取 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17562209/

相关文章:

android - TabHost/TabWidget - 缩放背景图像?

android - 使用 WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 获取所有 MotionEvents

jquery - codeigniter、jQuery Mobile、jQuery UI - 脚本未在首次加载时加载,仅刷新

java - 使用 ViewPager 和 Fragments 时无法动态更改 textView 的文本

android - 在 Android 中旋转文本

android - 通过将 Imageview 左上角视为 (0,0) 来获取 Imageview 的 X,Y 坐标

android - 如何读取android中的当前帧缓冲区?

android - 使用共享首选项来记住单击后隐藏的 TextView

Android以编程方式设置自定义 View 的高度和宽度

android - 为页眉和页脚添加一个 TextView