Results 1 to 9 of 9
  1. #1
    MondKopf is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Help with input class

    Hi,
    I'm extremely new to java and I'm struggling to understand the role 'class' and 'input'
    could someone please explain?
    also i tried to compile a basic example program using javac on terminal and it displayed the error message,

    Untitled-1.java:6: class input is public, should be declared in a file named input.java
    public class input{
    ^
    1 error

    what does this mean?

    thank you for any help

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    class is a keyword, for explanation here is a java tutorial What Is a Class? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)

    in your code input is the name of your class and your file as well.

    the error is telling you that the name of your class (which is input) is not the same with the name of the file itself, it should be save as input.java

  3. #3
    MondKopf is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks!
    Next problem, when i run the program the console says "exception in thread 'main' "
    any advice?

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Show your code and have you tried to search this on google. Im pretty sure lots of result will show.

  5. #5
    MondKopf is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    5/02/11 1:14:08 PM [0x0-0x35035].com.apple.JarLauncher[570] Exception in thread "main" java.util.NoSuchElementException: No line found
    5/02/11 1:14:08 PM [0x0-0x35035].com.apple.JarLauncher[570] at java.util.Scanner.nextLine(Scanner.java:1516)
    5/02/11 1:14:08 PM [0x0-0x35035].com.apple.JarLauncher[570] at input.main(input.java:15)

  6. #6
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    We cannot tell you where is the error with just the error message we need the source code, your code.

  7. #7
    MondKopf is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    import java.util.*;
    import java.io.*;


    public class input{
    public static void main(String args[])
    {

    Scanner read = new Scanner(System.in);
    boolean run = true;
    String data = "";
    do{
    System.out.println("\nLogging Keystrokes...");
    data = read.nextLine();
    System.out.println(data);
    }while(run);


    }}

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  9. #9
    MondKopf is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    could you explain how you did it so i can check if I'm doing it correctly?
    I'm using Mac btw

Similar Threads

  1. Keyboard Input In A Seperate Class?
    By FatalSylence in forum New To Java
    Replies: 6
    Last Post: 10-12-2010, 06:29 AM
  2. Replies: 1
    Last Post: 09-30-2010, 03:36 AM
  3. Input output without string class
    By surenq1 in forum New To Java
    Replies: 4
    Last Post: 06-13-2010, 04:18 PM
  4. Replies: 8
    Last Post: 06-27-2009, 06:35 PM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •