为什么 heroku 给我这个 "incompatible type" 错误?
Why does heroku give me this "incompatible type" error?
我正在尝试在 Heroku.com 上部署我的 discord 机器人,但是我收到了一个奇怪的错误...
这是引发错误的 class 的代码:
package main.Events.lavaplayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
import net.dv8tion.jda.api.audio.AudioSendHandler;
import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
public class AudioPlayerSendHandler implements AudioSendHandler {
private final AudioPlayer audioPlayer;
private final ByteBuffer buffer;
private final MutableAudioFrame frame;
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
this.audioPlayer = audioPlayer;
this.buffer = ByteBuffer.allocate(1024);
this.frame = new MutableAudioFrame();
this.frame.setBuffer(buffer);
}
@Override
public boolean canProvide() {
return this.audioPlayer.provide(this.frame);
}
@Nullable
@Override
public ByteBuffer provide20MsAudio() {
return this.buffer.flip();
}
@Override
public boolean isOpus() {
return true;
}
}
这段代码在使用 Intellij 编译时没有给我任何问题,但是当我尝试将它部署到 Heroku 时,他们给我这个错误:
error: incompatible types: java.nio.Buffer cannot be converted to @org.jetbrains.annotations.Nullable java.nio.ByteBuffer
return this.buffer.flip();
flip
returns 一个 Buffer
而不是 ByteBuffer 所以需要一个转换
public ByteBuffer provide20MsAudio() {
return (ByteBuffer) buffer.flip();
}
我正在尝试在 Heroku.com 上部署我的 discord 机器人,但是我收到了一个奇怪的错误... 这是引发错误的 class 的代码:
package main.Events.lavaplayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
import net.dv8tion.jda.api.audio.AudioSendHandler;
import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
public class AudioPlayerSendHandler implements AudioSendHandler {
private final AudioPlayer audioPlayer;
private final ByteBuffer buffer;
private final MutableAudioFrame frame;
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
this.audioPlayer = audioPlayer;
this.buffer = ByteBuffer.allocate(1024);
this.frame = new MutableAudioFrame();
this.frame.setBuffer(buffer);
}
@Override
public boolean canProvide() {
return this.audioPlayer.provide(this.frame);
}
@Nullable
@Override
public ByteBuffer provide20MsAudio() {
return this.buffer.flip();
}
@Override
public boolean isOpus() {
return true;
}
}
这段代码在使用 Intellij 编译时没有给我任何问题,但是当我尝试将它部署到 Heroku 时,他们给我这个错误:
error: incompatible types: java.nio.Buffer cannot be converted to @org.jetbrains.annotations.Nullable java.nio.ByteBuffer return this.buffer.flip();
flip
returns 一个 Buffer
而不是 ByteBuffer 所以需要一个转换
public ByteBuffer provide20MsAudio() {
return (ByteBuffer) buffer.flip();
}