我寫這段代碼:Java接口繼承
package sample;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusInterfaceName;
import org.freedesktop.dbus.DBusConnection;
@DBusInterfaceName("org.mpris.clementine")
interface Player extends DBusInterface, java.rmi.Remote {
void Pause();
}
class Main {
public static void main (String[] args) throws org.freedesktop.dbus.exceptions.DBusException, java.lang.InterruptedException {
DBusConnection dc = DBusConnection.getConnection(DBusConnection.SESSION);
Player player = (Player) dc.getRemoteObject("org.mpris.clementine", "/Player");
player.Pause();
dc.disconnect();
}
}
而且在線路得到一個錯誤
Player player = (Player) dc.getRemoteObject("org.mpris.clementine", "/Player");
它說,
Exception in thread "main" java.lang.ClassCastException: $Proxy2 cannot be cast to sample.Player
我知道問題出在繼承誤解或者這樣的行爲。我已經徹底搜尋,但我找不到答案。如何正確書寫這一行?那錯誤是什麼?
的問題是,你認爲你會得到一些擴展/實現的球員,但你不是。你得到某種自動生成的代理,不擴展/實現播放器。也許它的名單?我不知道。我建議在那裏設置一個斷點,並運行一些instanceof檢查來查看你有什麼。你可以發佈這個連接的另一面嗎? 「/ Player」下的「綁定」是什麼? –
radai