问题出现的情形:在安装完Oracle之后,使用命令行打开sqldeveloper时,出现如下问题:
问题:No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:126)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.Toolkit$2.run(Toolkit.java:860)
at java.awt.Toolkit$2.run(Toolkit.java:855)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
at java.awt.Toolkit.getEventQueue(Toolkit.java:1734)
at java.awt.EventQueue.isDispatchThread(EventQueue.java:1043)
at javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1361)
at oracle.ide.osgi.boot.SplashScreenImpl.SynchronizeWithEdt(SplashScreenImpl.java:531)
at oracle.ide.osgi.boot.api.SplashScreen.createInstance(SplashScreen.java:66)
at oracle.ide.osgi.boot.OracleIdeLauncher.showSplashScreen(OracleIdeLauncher.java:821)
at oracle.ide.osgi.boot.OracleIdeLauncher.main(OracleIdeLauncher.java:113)
原因:启动sqldeveloper的用户不合适,也算是权限问题,可参考:linux 终端启动图形化程序界面时报错:No protocol
这是因为Xserver默认情况下不允许别的用户的图形程序的图形显示在当前屏幕上. 如果需要别的用户的图形显示在当前屏幕上, 则应以当前登陆的用户, 也就是切换身份前的用户执行如下命令
xhost +
远程访问时也会出现类似问题:
第一步:用root登陆linux,启动vnc服务;
第二步:根据vnc起来的端口,设置export DISPLAY=localhost:1(1表示vnc在第一个tty上启动的);
第三步:执行xhost +,并且提示“access control disabled, clients can connect from any host”才正确。
解决办法:我是先登陆到oracle用户,然后再登陆(su ***)到安装oracle数据库时的用户,再su oracle 用户,之后在命令行启动sqldeveloper就可以了。