在按钮上设置onclick事件时出错

时间:2011-08-17 07:41:38

标签: android android-layout

我已经创建了一些xml布局和i java文件,一些xml文件具有相同的按钮ID,我在此创建onClick事件, 当我单击此按钮时,它会生成如下所示的错误

08-17 01:08:12.357: ERROR/AndroidRuntime(22434): java.lang.StackOverflowError
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at java.util.HashMap.containsKey(HashMap.java:313)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.provider.Settings$NameValueCache.getString(Settings.java:494)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.provider.Settings$System.getString(Settings.java:575)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.provider.Settings$System.getInt(Settings.java:624)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.media.AudioManager.querySoundEffectsEnabled(AudioManager.java:1089)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.media.AudioManager.playSoundEffect(AudioManager.java:1042)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.ViewRoot.playSoundEffect(ViewRoot.java:2478)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.playSoundEffect(View.java:8309)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2363)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(View.java:2364)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at com.widgets.CheckBoxClass.onClick(CheckBoxClass.java:44)
08-17 01:08:12.357: ERROR/AndroidRuntime(22434):     at android.view.View.performClick(V

1 个答案:

答案 0 :(得分:1)

我有答案:

我使用过该代码:

public void onClick(View v) {
    if(v.getId() == R.id.xCBApple){      
            Toast.makeText(CheckBoxClass.this,"Apple is Chedked",Toast.LENGTH_SHORT);
    }
    if(jBackButton.performClick())
    {
            Intent intent = new Intent(CheckBoxClass.this,AndroidWidgetsActivity.class);
            startActivity(intent);
    }
}

但我必须使用v.getId()== R.id.backButton而不是jBackButton.performClick()并且错误消失了但我不知道有关performClick(),任何人都可以知道吗?

感谢 拉胡