1

So I just started learning java in treehouse.com I've done the basics but when i try everything I've learnt there on the intellij idea ide nothing works.

I've already searched the internet trying to find a solution and I still cant find it, yea I've tried system.out but I've seen other people do it with just typing console too and if I try system.out on readline it doesn't work I'm literally confused.

I'm used to using the

console.println("Hello world!");

and

String name=console.readln("whats yo name: ");

and stuff like that on the treehouse workspace but everytime i try to do it on intellij idea it keeps getting an error.

it looks like this

package com.company;

import java.io.Console;

public class Main
{
    public static void main(String[] args)
   {
    console.println("dada");



   }
}
PGSystemTester
  • 4,265
  • 2
  • 14
  • 39
  • @ElliottFrisch i studied the java basics on treehouse not javascript – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:05
  • 1
    "_intellij idea it keeps getting an error._" What specific error do you get ? – JonasCz Apr 04 '16 at 12:05
  • What would be the console variable? I am also confused with your question posed like that. Were you trying to use something like System.out.println("String here"); ? – Reuel Ribeiro Apr 04 '16 at 12:06
  • @JonasCz it wont compile – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:06
  • @ReuelRamosRibeiro it wont compile if i just try to print by using console.println("blablabla"); – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:07
  • Yes, but it tells you what the reason is that it can't compile, that's what I mean. What is the compiler error you're getting ? – JonasCz Apr 04 '16 at 12:07
  • @JonasCz Error:(9, 9) java: cannot find symbol symbol: variable console location: class com.company.Main – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:08
  • 1
    Treehouse should spend more time on Stack Overflow. – Tim Biegeleisen Apr 04 '16 at 12:09
  • @AhmadIzzudinAlifyandra But console just by itself is something that does not exist in Java world. You must use the System.out.println() method do print something to the console. At treehouse, they probably have this method available at your code scope just because of simplicity. – Reuel Ribeiro Apr 04 '16 at 12:09
  • @AhmadIzzudinAlifyandra **Never** put more information into comments. Always update your question. And please spend some time on the stack overflow help center in order to understand what makes a good question. – GhostCat Apr 04 '16 at 12:11
  • @AhmadIzzudinAlifyandra have you started by using the chapter specific workspace in treehouse. I have done several courses in treehouse and if you follow along pretty much every line of code works. Clearly you havent done everything that the chapter says. Try the workspace also you can check the course on setting up IntelliJ, as you could be missing the SDK for all you know. –  Apr 04 '16 at 12:12
  • @ReuelRamosRibeiro oh, can you tell me how do i readline then because it doesnt work if i console.readline nor if i system.out.readline. Can you give me a link to the references thanks – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:12
  • @AhmadIzzudinAlifyandra have you even instatiated this console object? `Console console = new Console()` –  Apr 04 '16 at 12:13
  • @Clockwork theres a course for intellij idea?! – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:13
  • @Clockwork yes ive tried that doesnt work – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:13
  • @AhmadIzzudinAlifyandra yes, the name is Setting up your development environment. However I would recommend using the Workspace for Java Basics as you'd understand better what goes on under the hood. –  Apr 04 '16 at 12:15
  • Reading your updated code, yes, it won't work, since you don't instantiate the console object. And: `Console` may not work in an IDE: [Java: How to get input from System.console()](http://stackoverflow.com/q/4644415) You could use Scanner instead for getting input: [How can I read input from the console using the Scanner class in Java?](http://stackoverflow.com/q/11871520) – JonasCz Apr 04 '16 at 12:16
  • Yes indeed Console will not work on any IDE, but the code will work on your workspace. –  Apr 04 '16 at 12:17
  • @Clockwork so i should finish the treehouse java track first your saying before i can fiddle around in an actual ide? – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:20
  • Well you can always use an IDE, but that would provide you a whole bunch of support which you'd need during production. Doing in the workspace without code help and following the course exactly will help learning and understanding what you're doing a lot better. –  Apr 04 '16 at 12:27
  • @Clockwork oh well thanks i thought i could instantly use an ide by just learning the basics on treehouse just like i did with c# – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:29
  • thanks everyone for da help – Ahmad Izzudin Alifyandra Apr 04 '16 at 12:29

1 Answers1

1
Console console = new Console()

This code won't work on IntelliJ.

To take input in an IDE use the following code.

Scanner sc = new Scanner(System.in)
String in = sc.nextLine();
System.out.println(in);

You can also use the older way,

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)));
String in = br.readLine();
  • I've updated my answer, you can use readline, but not on the console object. –  Apr 04 '16 at 12:25