我目前正在从事Java项目,现在有点卡住了,遇到了问题。我是Java初学者,对其他知识不了解。我的播放器有问题。有人说“不兼容的类型:void无法转换为PLayer”不知道我的代码有什么问题。 PLayer是我必须传递值的类。希望得到专家的建议。非常感谢!
private void AddJButtonActionPerformed(java.awt.event.ActionEvent evt) {
final int MAX_NUMBER = 1000;
final double BET_COST = 100;
final double EXACT_MATCH = 10000;
final double THREE_DIGITS_MATCH = 3000;
final double TWO_DIGITS_MATCH = 2000;
final double ONE_DIGIT_MATCH = 1000;
{output.delete(0,output.length());
String selectedPlayerName = jList2.getSelectedValue();
PLayer thePlayer;
thePlayer = searchmusic(selectedPlayerName);
if(numberAsString.length() > 0 && !numberAsString.equals("")&&
numberAsString != null && thePlayer != null &&
thePlayer.getBalance() >= BET_COST)
您已声明该播放器为播放器类型:
Player thePlayer;
但是您将其分配给名为searchmusic的函数的返回。您没有显示searchmusic函数,但很有可能它的定义如下:
void searchmusic(String selectedPlaydName) {
// The code of the function
}
该函数应返回一个Player,而不是void。 void表示该函数不返回任何内容。