Results 1 to 6 of 6

Thread: Help with code

  1. #1
    Idocrase is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default Help with code

    Can you tell me why codes not working, i'm just starting off learning java and haven't quite gotten the swing of things yet.

    In my main:

    public static void main(String[] args) {

    TWapp T = new TWapp();

    T.OpenFile();
    T.ReadFileInt();
    T.ReadFileName();
    T.Close();
    }
    }

    Other class:


    private Scanner x;

    public void OpenFile(){
    try{
    x = new Scanner(new File("TWFile.txt"));
    }
    catch(Exception e){
    System.out.println("NO GO!");
    }
    }

    public void ReadFileInt(){
    while(x.hasNextInt()){
    int Spear = x.nextInt();
    int Sword = x.nextInt();
    int Axe = x.nextInt();
    int Archer = x.nextInt();
    int Scout = x.nextInt();
    int LightCalvery = x.nextInt();
    int MountedArcher = x.nextInt();
    int HeavyCalvery = x.nextInt();
    int Ram = x.nextInt();
    int Cat = x.nextInt();
    System.out.println(Spear);
    }
    }
    public void ReadFileName(){
    while(x.hasNext()){
    String FileName = x.next();
    System.out.println(FileName);
    }
    }
    public void Close(){
    x.close();
    }

    }


    I left out the top of the code, but rest assured its there.

    I also have a file namedTWFile and is .txt in the dir with the codee itself:

    When I run it it says build successful but it doesn't output anything even though I have numbers in the file.

    Any suggestions?

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,600
    Rep Power
    5

    Default Re: Help with code

    You need to show a Short, Self Contained, Correct Example of your program. And include only the pertinent parts of the program.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Idocrase is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default Re: Help with code

    I am sorry for the size but since i'm not getting any errors I cannot point you to the problem, its just that the code doesn't do what it was designed to.

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

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Help with code

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,990
    Rep Power
    5

    Default Re: Help with code

    Quote Originally Posted by Fubarable View Post
    Then use a debugger for before you can solve an error, you must first identify it.
    Or just pepper the code with System.out.println statements to print out what it is doing. Debuggers are a huge benefit, but you need to have a basic understanding of program flow first before it will really make any sense.

Similar Threads

  1. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  2. Replies: 3
    Last Post: 08-10-2011, 09:17 AM
  3. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  4. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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