Java 为什么 sysout 不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18027355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:52:14  来源:igfitidea点击:

Why sysout won't work?

javaeclipsecode-snippets

提问by Zoe

I checked the preferences settings in my Eclipse, it's all set to default with sysout option on, but when I typed sysout in eclipse, it won't automatically go into System.out.println(). I've checked several other related topics which mention ctrl + space. It is a shortcut for input method on my computer. I don't know if this is related to my unable to use the sysout. If not, please let me know how I can get my sysout working. If yes, please kindly let me know how I can reset 'ctrl + space' or set other shortcut for content assistant.

我检查了 Eclipse 中的首选项设置,在 sysout 选项打开的情况下,所有设置都设置为默认值,但是当我在 Eclipse 中键入 sysout 时,它不会自动进入System.out.println(). 我已经检查了其他几个提到ctrl + space. 这是我电脑上输入法的快捷方式。我不知道这是否与我无法使用sysout有关。如果没有,请告诉我如何让我的 sysout 工作。如果是,请告诉我如何重置“ctrl + space”或为内容助手设置其他快捷方式。

回答by óscar López

You have topress Ctrl + Spacefor the sysout(or equivalently: syso) shortcut to work in Eclipse, as sysoutis not part of Java in anyway, on the contrary: it's an abbreviation introduced in Eclipse that only works after you press Ctrl + Spaceand expands to System.out.println().

必须Ctrl + Spacesysout(或等效:syso)的快捷方式在Eclipse中工作,sysout是不是Java的一部分,无论如何,与此相反:这是在Eclipse推出的缩写,只有你按下后的作品Ctrl + Space,并扩展到System.out.println()

By the way, syserr(or equivalently: syse) will expand to System.err.println()after pressing Ctrl + Space.

顺便说一句,syserr(或等效地:syse)将System.err.println()在按下 后扩展到Ctrl + Space

回答by q99

Is there anyway to modify the keyboard shortcuts in eclipse?here you can find out how to make a custom shortcut Window -> Preferences -> General -> Keys

有没有办法修改eclipse中的键盘快捷键?在这里您可以了解如何制作自定义快捷方式Window -> Preferences -> General -> Keys

edit: here is a video tutorial http://eclipseone.wordpress.com/2010/02/03/how-to-manage-keyboard-shortcuts-in-eclipse/

编辑:这是一个视频教程http://eclipseone.wordpress.com/2010/02/03/how-to-manage-keyboard-shortcuts-in-eclipse/

回答by D15

Eclipse Shortcuts:

Syso + Control + Space:     Puts System.out.println()
Alt + Shift + R:            Rename
Control + F11:              Run
ALT + Up/Down:              move the current line (or lines selected) in the editor up or down 
Control + Shift + O:        Import
Control + I:                Indent
Control + D:                Delete Line
Control + H:                Search Your Entire Project

回答by Winds

For me sysout in eclipse created in two lines. println() in new line..Then I found myself how to avoid this and get System.out.println in one line ..go to Windows > Preferences > Java->Templates (or type templates on search field in top left corner box).Then In template configuring section uncheck "use code formatter"..thats it.. :)

对我来说,eclipse 中的 sysout 是在两行中创建的。println() 在新行中..然后我发现自己如何避免这种情况并在一行中获取 System.out.println.. 转到 Windows > Preferences > Java->Templates(或在左上角框中的搜索字段上键入模板).然后在模板配置部分取消选中“使用代码格式化程序”..就是这样..:)

System.out
         .println();

回答by Muhammad Gelbana

Eclipse > Preferences > Java > Editor > Content Assistant > Advanced

Make sure Template Proposalsis checked in one of the shown lists.

确保在显示的列表之一中选中模板提案

回答by kucing_terbang

Seems like you in windows and your keyboard shortcut for eclipse is got replaced with the system keyboard shortcut for language. well, either you replace it the keyboard combination to shows the template proposals by :

似乎您在 Windows 中,并且您的 eclipse 键盘快捷键已被语言的系统键盘快捷键替换。好吧,要么将其替换为键盘组合以通过以下方式显示模板建议:

1. open the preferences dialog
2. go to general -> keys
3. in the search dialog, find the command `Content Assist`
4. change the binding and then click OK button

or, you can change the combination key to change the language in the Text Services and Input Languageand then go to the Advanced Key Settings tab and then change the key sequence.

或者,您可以更改组合键以更改 中的语言Text Services and Input Language,然后转到“高级键设置”选项卡,然后更改键序列。

回答by dan.ros.

Select in the menu bar "Window > Preferences > Java > Editor > Templates" deselect at the lower end of window: "Use code formatter"

在菜单栏中选择“Window > Preferences > Java > Editor > Templates”在窗口的下端取消选择:“Use code formatter”

enter image description here

在此处输入图片说明

回答by PbxMan

In my case it didn't work because ctrl+space was being used by another program Ubuntu(I-Bus) in my case ref. hereTry changing ctrl-space by another key combination in general->keys to find out if this is causing the problem.

就我而言,它不起作用,因为在我的情况下,另一个程序 Ubuntu(I-Bus) 正在使用 ctrl+space。在这里尝试通过其他组合键更改 ctrl-space 以查看是否是导致问题的原因。

回答by Chris

After trying all the answers above with no success I found another reason why Ctrl+Space could be prevented from working.

在尝试了上述所有答案但没有成功后,我发现了另一个原因,可以阻止 Ctrl+Space 工作。

In my instance Ctrl+Space worked for some projects in the workspace but not others. I discovered that the project that it did not work for did not have the jdk in the build path, instead it had the jre for the application server (weblogic 12). The application ran fine on the server but Ctrl+Space to open the template proposals didn't work and other things like syntax highlighting were not quite right.

在我的实例中,Ctrl+Space 对工作区中的某些项目有效,但对其他项目无效。我发现它不起作用的项目在构建路径中没有 jdk,而是在应用程序服务器(weblogic 12)中有 jre。该应用程序在服务器上运行良好,但 Ctrl+Space 无法打开模板建议,并且语法突出显示等其他内容不太正确。

I hope this helps anyone who comes to this questions 3 years after it was asked (Like I did).

我希望这可以帮助任何在被问到这个问题 3 年后(就像我一样)提出这个问题的人。

回答by Mak Insane

public static void main(String[] args)

This public static void... blah blah has to be put for the sysoutto work

public static void... blah blah 必须投入sysout工作