I am new learning Java in IntelliJ and I have a problem edit configurations which I don't know how to run my program HelloWorld. Some pictures are as below:
This is my code.
This is what presents after I click Run
It appears Edit configurations.
And then I don't know what should I do.
I think you have not set an SDK for your project, try adding an SDK, if that doesn't work you have to download and install it first. And next time please add your code as text with the "{ }" tool not as a picture.
And to print something into the console you have to do it like this:
System.out.println("Hello World")
And also if you want to print to the terminal, the right way to do it is...
System.out.println("Text here")
And if you dont want to break the line when writing, you can do this.
System.out.print("Text here")
When using "" inside of an print method, it indicates that you want to print a String.
Related
The Error is shown when I input anything in the output window
As the name implies, output window is only for displaying output. It seems that you're using VSCode Coderunner extension, which by default runs program in output window.
To change it to terminal, simply put :
"code-runner.runInTerminal": true
In your VSCode User Settings (shortcut: Ctrl + ,).
In general, this problem seems to occur in code runner. But when I was Doing settings according to the upper Most Upvoted Answer, I was not able to edit Json File Correctly as It's showing some error. So, If this is the case, You can do this too.
GO TO VS CODE SETTINGS.
IN USER SEARCH BAR, Type CODE RUNNER TERMINAL
Now, Check the option of Run in Terminal. Voila!! Good To Go!
Solution Image
Type the input in the console, not the output window.
you cant input anything in output window.
if you want make any change or edit in output section you should first do debug in console box and then you can make any change you want
Use the shortcut command Shift + Ctrl + X to bring out the extensions side bar,
Now in the search extensions in market place entry input "#installed code runner",
Make sure you have installed code runner extension (If you haven't do that now),
Next right click on the extension and select extension settings,
Scroll down to run in terminal, finally select the check button.
That should do it.
The output window is only for outputs. Use your terminal for input-based code.
To get output in terminal of vscode :
step1:
Click Ctrl+, or open the settings
step2:
search for code runner
step3:
turn on the Run in terminal checkboxscreenshot is included
I know Eclipse has default keybindings (copy, paste, etc), and you can set keybinds for commands they've already decided on (Generate Setter/Getter, etc) but is it possible to set up a custom command?
For example, I can press Shift+F5 and it'll automatically type or paste "System.out.println();" for me.
In Eclipse Preferences, go to Java->Editor->Templates
Click on "new" to create a new template.
In your template, write in the "pattern" textarea the command you want to be pasted.
For example :
throw new IllegalArgumentException("");
And in the "name" textbox, write the word that matches to that command.
Then, in Eclipse, in your Java Editor, write that word + auto-completion. Eclipse will propose you,among others may be, your template.
The sysout command name is that template :
System.out.println(${word_selection}${});${cursor}
I wanted to add a text prompt for my JFormattedTextField and I searched it on google on how I could do this. I got a lot of hits for the following code below but when I put it into my code in eclipse it doesn't recognize any of it. Can someone tell me why?
Here are two possible ways to add a text prompt:
PromptSupport.setPrompt("prompt", textComponent);
TextPrompt p = new TextPrompt("text", textComponent);
I got it from the following link:
How to display a default message in JTextField java
the most probable reasons why eclipse doesn't recognize any of these classes are because they are not a part of the JDK.
PromptSupport is a part of the XSwingX library. If you want to use this library for setting PromptText, you will have to download the jar and add it to the build path of the project.
I am not sure whether TextPrompt is the class XSwingX as well.
I am using a few functions in my application which i want to replace with other functions (to make it backward compatible)
My question : is it possible to find & replace some specific text in all java files in a package with some tool, or do i have to do it manually on every java file? I have a LOT of java files in the package.
For eg : i want to replace
getExternalCacheDir()
with something like
Environment.getExternalStorageDirectory + "/Android/data/<package_name>/cache/"
the IDE i'm using is Eclipse Helios. Any solutions?
Use Search - File... in Eclipse, search for getExternalCachDir() in *.java, then right click in the Search view, choose Replace All..., enter the replacement text, and click OK.
In eclipse, Just do
right click on function->Refector->Rename
or
select method + press shift+alt+R
This will change your method name through out the project.
Just installed Eclipse Helios (Win7 64) and I'm having a strange problem. I type syso-Ctrl-Space which is expected to complete to System.out.println("") but it doesn't work! I searched the web for about an hour now, I set Preferences > Java > Editor > Content Assist to defaults, nothing. Everything else seems to work. Ideas?
To be clear: the shortcut works, it completes everything except "syso" as seen so far, on syso (also tried sysout) it says "No Default Proposals". I couldn't find this kind of shortcuts in the Content Assist, but I set them to default anyway.
If you still cant get auto-completion working,try enabling the Template proposals under Content assist menu.This is the exact location,
Windows->Preferences->Java->Editor->Content Assist->Advanced
And make sure you have only one entry for syso(Under Templates menu).
I believe the right template is "sysout" and I believe this can be configured somewhere but could not tell you where. Try sysout and then Ctrl+Space
It's a template, you can find all templates under
Window -> Preferences -> Java -> Editor -> Templates
There you can see that the template name is "sysout" this will then trigger the string substitution for System.out.writeln() but you can change both the template name (if you prefer syso) and/or the actual code produced by invoking the template
Cheers
I am using Eclipse Galileo and had the same problem. Even after trying the above proposed solutions but it didn't work. After making the below change it finally comes out.
Go to Windows->Preferences->Java->Editor->Templates
Select sysout template and edit it.
Change the context from Java statement to Java.
And it worked for me. I hope this will be helpful for you.
As Peter stated, it is under Window -> Java -> editor -> templates.
Look for the line with the following values.
sysout "Java Statements" "Print to standard out" "on"
the preview should be as follows...
System.out.println(${word_selection}${});${cursor}
Your cursor needs to be located in a place where it would be legal to get that line. If your cursor is within a method definition and you type syso you will get the replacement. However if your cursor is in the portion of the text outside of any method definition, say where you declare variables for your class for instance, then syso will not suggest the illegal line system.output.println();.
I had this problem, read all the answers here, became convinced that it MUST be working in my copy, and realized I had been typing syso BELOW the closing } of my last method instead of in the method.
Eclipse on!
You may try to set the shortcut of Content Assist with ALT+L, if it works, then you can choose your favorite shortcut again. (The shortcut Ctrl+Space conflicts with the shortcut of switching input method). In eclipse on linux, the shortcut of Word Completion is ALT+/, so if you set this as the shortcut of Content Assist it also conflicts.)
Just go to the below address:
Windows->Preferences->Java->Editor->Content Assist->Advanced
and click restore default..........that's all
its work like a charm again.
Also check in this eclipse menu:
Windows -> Preferences -> Java -> Appearance -> Type Filters
If you see java.* or javax.* here then try removing it (or Restore Default will do the job) and see that works, it did for me.
Just found the solution for Eclipse Luna: write syso and press CTRL+Space and click on "enable intelligent code completion" and you are set.
I am sure you can find it somewhere in the options as well but this way it is fast and easy!
DIRTY WORKAROUND:
You can try out the following AutoHotkey-Code if you're still struggling like I am (STILL haven't been able to fix it myself)
#persistent
#ifwinactive ahk_class SWT_Window0 ; eclipse java
:*:syso::
sendraw System.out.println()`;
loop, 2
send {left}
return
#ifwinactive
You need to write this in a .ahk file and run it (AutoHotkey needs to be installed). You might wanna put this file into your startup folder. It's a very useful tool, you might wanna expand it one day.
You might have overlapping shortcuts.. Goto 'Overview' than the 'Keys' subsection. Type "ctrl +space" in the 'filter text' section. You should see the "content assist" and probably another command with the same shortcut. If another shortcut does exists, change its shortcut to something else.