【问题标题】:android:onClick attribute stopped working, can't find method in activityandroid:onClick 属性停止工作,在活动中找不到方法
【发布时间】:2013-01-22 11:55:10
【问题描述】:

我有一堆这样的按钮

<cz.applmartin.quicksketch.Gui.Buttons.CopyDragableImageButton
android:id="@+id/b_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="b_settings"
android:background="@drawable/s_settings"
/>

在活动中对应这样的方法

public void b_settings(View view){
    Intent intent = new Intent(Main.getInstance(), SettingsActivity.class);
    startActivity(intent);
}

所有方法都存在并且是公开的。一切似乎都很好。我工作了很长时间。比它突然开始给出这个错误。

java.lang.IllegalStateException: Could not find a method b_settings(View) in the activity class cz.applmartin.quicksketch.Main for onClick handler on view class cz.applmartin.quicksketch.Gui.Buttons.CopyDragableImageButton with id 'b_settings'

但我确信该方法实际上存在于 Main 中并且是公开的并且具有正确的签名。错误仅在具有较旧 api 的设备和模拟器上显示。 (测试2.2 2.3) 在新的 apis (4.*) 上一切正常。 据我所知,我没有用按钮或活动中的相应方法更改有关 xml 的任何内容。它只是无缘无故停止工作。

在 manifest min sdk 是 8 和 target 是 10。在属性中构建目标是 4.2

以前有人遇到过这种情况吗?有什么线索吗?谢谢

【问题讨论】:

    标签: android android-layout android-activity


    【解决方案1】:

    我以为你把同一个项目和另一个项目一起做了。但是你在布局中使用

    【讨论】:

    • 对不起,我不理解你。你能试着更好地解释你的想法吗?谢谢。
    • 如果您的项目包名与 cz.applmartin.quicksketch.Gui 不同。那么它会给出错误
    • 项目包名是cz.applmartin.quicksketch。但这几乎不是问题,因为它以前是一样的并且有效。
    猜你喜欢
    • 1970-01-01
    • 2017-09-07
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    相关资源
    最近更新 更多