• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

Compile errors!! :(

UserUnknown

eXo's Resident Brony
I'm having issues with the program I'm trying to compile. Here's my code:

[highlight=java]
import java.util.Scanner;

class apples{
public static void main (String args[]){
Scanner logan = new Scanner (System.in);
System.out.println(logan.nextLine));
}
}[/highlight]

Can someone help me? D:
 
B

Bizarre

Guest
What program are you using to code?
Also what's your error?
 

UserUnknown

eXo's Resident Brony
Error said:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
logan.nextLine cannot be resolved or is not a field
Syntax error on token ")", delete this token"

Is the error that comes up. I've deleted that token, and still get an error.


Error after fix said:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
logan.nextLine cannot be resolved or is not a field

I'm running Eclispe.
 
B

Bizarre

Guest
I'm pretty sure logan.nextLine doesn't work inside of a out print statement, what your doing is out printing the user being able to input, which makes no sense.

Code:
   1.
      import java.util.Scanner;
   2.
       
   3.
      class apples{
   4.
          public static void main (String args[]){
   5.
              Scanner logan = new Scanner (System.in);
   6.
          logan.nextLine;
   7.
          }      
   8.
      }

That should work, although I don't know your program so I can't help too much.

EDIT: What are you trying to do? Because what you showed me makes no sense and won't work. Declare logan as a string
 
B

Bizarre

Guest
Code:
import java.util.Scanner;

class apples{
  
  public static void main (String args[]){
    
    String logan;
    Scanner input = new Scanner (System.in);
    
    System.out.println ("Enter anything");
    logan = input.nextLine();
    
    System.out.println ("You wrote: " + logan + ".");
  }
}

That is how it should look.
 

Greyone

Funny Little Green Ghouls
cool people use joptionpane
Code:
import javax.swing.JOptionPane;

public class Sythril
{
	public static void main(String[] args)
	{
		String strHowGayCanYouBe;
		String outputStr;
		
		strHowGayCanYouBe = JOptionPane.showInputDialog
				("Enter whatever");

		outputStr = strHowGayCanYouBe;
			
			JOptionPane.showMessageDialog(null, outputStr, 
				"Sythril Is Soooo Gay",
				JOptionPane.INFORMATION_MESSAGE);
			System.exit(0);
			
}
}
 

Moca

New Member
Code:
System.out.println(logan.nextLine[B])[/B]);
You are missing a parenthesis. Add a ( to make your code look like this:
Code:
System.out.println(logan.nextLine());

There is no need to recode your program as nick48 has done.
 

Raz5

beep = (char) 7;
I'm pretty sure logan.nextLine doesn't work inside of a out print statement, what your doing is out printing the user being able to input, which makes no sense.

Code:
   1.
      import java.util.Scanner;
   2.
       
   3.
      class apples{
   4.
          public static void main (String args[]){
   5.
              Scanner logan = new Scanner (System.in);
   6.
          logan.nextLine;
   7.
          }      
   8.
      }

That should work, although I don't know your program so I can't help too much.

EDIT: What are you trying to do? Because what you showed me makes no sense and won't work. Declare logan as a string

It does work. Although it's a little weird writing System.out.println(logan.nextLine), it does make some sort of sense.

Basically, you can use it to give out an echo of what you just wrote using the Scanner. And you can add something to what you wrote in the end, as so:

[highlight=Java]
import java.util.Scanner;

public class apples{

public static void main (String args[]){

Scanner logan = new Scanner (System.in);
System.out.println(logan.nextLine() + " is ghey");

}
}

[/highlight]

No compilation errors what so ever using this code.
 
Top