2

I added ProGuard to my Android project using default settings, and it broke my code.

On the first screen, I have a Button like this:

  <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="onSaveButtonClick" />

And I have a method in the Class:

public void onSaveButtonClick(View view){
 // some code 
}

When ProGuard disabled, everything works just fine. When enabled, on clicking the button I get this error:

05-17 16:04:54.099: E/AndroidRuntime(1181): java.lang.IllegalStateException: Could not find a method onSaveButtonClick(View) in the activity class xxxx for onClick handler on view class android.widget.Button with id 'xxxxx'

Any ideas why this happened?

4

1 回答 1

3

Proguard 正在将您的方法“onSaveButtonClick”更改为“a”。它不会更新您的 XML 文件,因此 Android 无法再找到它。您应该以编程方式设置您的点击处理程序(在视图上使用 setOnClickListener)或遵循 Keyser 发布的 SO 问题中链接的建议。

于 2012-05-17T20:36:53.503 回答