gpt4 book ai didi

java - "The value of the local variable SoundButton38 is not used"但我想使用它?

转载 作者:行者123 更新时间:2023-12-01 13:41:43 25 4
gpt4 key购买 nike

我是编程新手,我正在 eclipse 中编程。

我正在创建一个简单的音板,但收到警告“未使用局部变量 SoundButton38 的值”,但我想使用该变量。

SoundButton1-37 正在工作并且没有错误,但 38-63 确实有警告。我不确定是什么原因造成的以及为什么会发生。

这是我的代码 fragment ,其中出现警告(35、36 和 37 没有警告:

            Button SoundButton35 = (Button)findViewById(R.id.sound35);
SoundButton35.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mSoundManager.playSound(35);

}
});
Button SoundButton36 = (Button)findViewById(R.id.sound36);
SoundButton36.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mSoundManager.playSound(36);

}
});

Button SoundButton37 = (Button)findViewById(R.id.sound37);
SoundButton35.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mSoundManager.playSound(37);

}
});

Button SoundButton38 = (Button)findViewById(R.id.sound38);
SoundButton35.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
mSoundManager.playSound(38);

}
});

这是我的代码的开头

package com.soundboardtest;

import com.soundboardtest.R;
import com.soundboardtest.SoundManager;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Soundboard extends Activity {
private SoundManager mSoundManager;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soundboardtest);

mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1, R.raw.sound1);
mSoundManager.addSound(2, R.raw.sound2);
mSoundManager.addSound(3, R.raw.sound3);
mSoundManager.addSound(4, R.raw.sound4);
mSoundManager.addSound(5, R.raw.sound5);
mSoundManager.addSound(6, R.raw.sound6);
mSoundManager.addSound(7, R.raw.sound7);
mSoundManager.addSound(8, R.raw.sound8);
mSoundManager.addSound(9, R.raw.sound9);
mSoundManager.addSound(10, R.raw.sound10);
mSoundManager.addSound(11, R.raw.sound11);
mSoundManager.addSound(12, R.raw.sound12);
mSoundManager.addSound(13, R.raw.sound13);
mSoundManager.addSound(14, R.raw.sound14);
mSoundManager.addSound(15, R.raw.sound15);
mSoundManager.addSound(16, R.raw.sound16);
mSoundManager.addSound(17, R.raw.sound17);
mSoundManager.addSound(18, R.raw.sound18);
mSoundManager.addSound(19, R.raw.sound19);
mSoundManager.addSound(20, R.raw.sound20);
mSoundManager.addSound(21, R.raw.sound21);
mSoundManager.addSound(22, R.raw.sound22);
mSoundManager.addSound(23, R.raw.sound23);
mSoundManager.addSound(24, R.raw.sound24);
mSoundManager.addSound(25, R.raw.sound25);
mSoundManager.addSound(26, R.raw.sound26);
mSoundManager.addSound(27, R.raw.sound27);
mSoundManager.addSound(28, R.raw.sound28);
mSoundManager.addSound(29, R.raw.sound29);
mSoundManager.addSound(30, R.raw.sound30);
mSoundManager.addSound(31, R.raw.sound31);
mSoundManager.addSound(32, R.raw.sound32);
mSoundManager.addSound(33, R.raw.sound33);
mSoundManager.addSound(34, R.raw.sound34);
mSoundManager.addSound(35, R.raw.sound35);
mSoundManager.addSound(36, R.raw.sound36);
mSoundManager.addSound(37, R.raw.sound37);
mSoundManager.addSound(38, R.raw.sound38);
mSoundManager.addSound(39, R.raw.sound39);
mSoundManager.addSound(40, R.raw.sound40);
mSoundManager.addSound(41, R.raw.sound41);
mSoundManager.addSound(42, R.raw.sound42);
mSoundManager.addSound(43, R.raw.sound43);
mSoundManager.addSound(44, R.raw.sound44);
mSoundManager.addSound(45, R.raw.sound45);
mSoundManager.addSound(46, R.raw.sound46);
mSoundManager.addSound(47, R.raw.sound47);
mSoundManager.addSound(48, R.raw.sound48);
mSoundManager.addSound(49, R.raw.sound49);
mSoundManager.addSound(50, R.raw.sound50);
mSoundManager.addSound(51, R.raw.sound51);
mSoundManager.addSound(52, R.raw.sound52);
mSoundManager.addSound(53, R.raw.sound53);
mSoundManager.addSound(54, R.raw.sound54);
mSoundManager.addSound(55, R.raw.sound55);
mSoundManager.addSound(56, R.raw.sound56);
mSoundManager.addSound(57, R.raw.sound57);
mSoundManager.addSound(58, R.raw.sound58);
mSoundManager.addSound(59, R.raw.sound59);
mSoundManager.addSound(60, R.raw.sound60);
mSoundManager.addSound(61, R.raw.sound61);
mSoundManager.addSound(62, R.raw.sound62);
mSoundManager.addSound(63, R.raw.sound63);

感谢您的帮助,我无法找到一个好的答案。

最佳答案

 Button SoundButton38 = (Button)findViewById(R.id.sound38);
SoundButton35.setOnClickListener(new OnClickListener() {

这里好像有错字,我认为应该是

 SoundButton38.setOnClickListener(new OnClickListener() { 

类似

 Button SoundButton37 = (Button)findViewById(R.id.sound37);
SoundButton35.setOnClickListener(new OnClickListener() {

应该是

SoundButton37.setOnClickListener(new OnClickListener() {

关于java - "The value of the local variable SoundButton38 is not used"但我想使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20696865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com