Results 1 to 11 of 11
  1. #1
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default unreachable statement.

    Im having quite a annoying problem with my program and was wondering if you guys could help me out and give me some advice. I keep getting this unreachable error in my GUI when i try to refer a string from a text box in order to make a file name out of the string type.

    take a look please. this is at the bottom of my gui. my text box refers to the method but i can't seem to figure out why it wont send over the name.


    private void job(String jobs) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    File newFile = new File(jobs,".txt"); <<<<<<<<<<<<<<ERROR HERE!!!!!!!!!!

    try{
    newFile.createNewFile();
    }
    catch (Exception e)
    {
    }
    try
    {
    FileWriter fileW = new FileWriter(newFile);
    try (BufferedWriter buffW = new BufferedWriter(fileW)) {
    buffW.write("this is cool.");
    buffW.newLine();
    buffW.write("yea man");
    }
    System.out.println("file written");
    }
    catch (Exception e)
    {}


    }
    ----------------------------------

    here is my text area
    private void jobNumberActionPerformed(java.awt.event.ActionEven t evt) {
    String jobs = jobNumber.getText();
    job(jobs);

    }

    please help.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: unreachable statement.

    The first thing your job() method does is throw an exception; the statements following it will never be executed; the compiler saw that and reported it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    thanks. what would you suggest i use for an exception? something to see if the file exists? sorry i'm kinda new to this.

  4. #4
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    I wrote this as my exception but it didn't seem to do much. still receiving error. @Jos you said" the first thing" is there more that I'm missing. I really appreciate your feedback.




    try{
    newFile.createNewFile();
    }
    catch (Exception e)
    {
    System.err.format("file named %s" +
    " already exists%n", jobs);

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: unreachable statement.

    Don't double post in the forum!
    I just answered this in your other thread, which I could have saved myself some time over if you hadn't decided to spam the forum.
    Please do not ask for code as refusal often offends.

  6. #6
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    Sorry tolls. I didn't know where it would go and it was my first post. i apologize.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,924
    Rep Power
    4

    Default Re: unreachable statement.

    I was in the midst of editing my reply to that effect. When I tried to submit, the thread was closed! Arrrggg!!

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

  8. #8
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    Thanks deleting the throw statement removed the error, but the file isnt being created. Is there another obvious mistake? it now looks like this

    public void job(String jobs) {

    File newFile;
    newFile = new File("C:/gsudicky/%s.txt",jobs);

    try{
    newFile.createNewFile();
    }
    catch (Exception e)
    {


    }

    try
    {
    FileWriter fileW = new FileWriter(newFile);
    try (BufferedWriter buffW = new BufferedWriter(fileW)) {
    buffW.write("this is cool.");
    buffW.newLine();
    buffW.write("yea man");
    }
    System.out.println("file written");
    }
    catch (Exception e)
    {}


    }

  9. #9
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    and here is my text box i entered the string into. maybe its not relaying the string properly? any advice is helpful, this is becoming a hairpulling problem this morning.

    private void jobNumberActionPerformed(java.awt.event.ActionEven t evt) {
    String j = jobNumber.getText();
    job(j);

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: unreachable statement.

    You are eating exceptions.
    If an exception is thrown in that code you ignore it.
    So add e.printStackTrace() inside your catch blocks.
    Please do not ask for code as refusal often offends.

  11. #11
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: unreachable statement.

    Thanks!!!! you are the best, i hope you know that. :)

Similar Threads

  1. Unreachable statement. please take a look.
    By gbonecapone in forum Advanced Java
    Replies: 1
    Last Post: 05-22-2013, 01:52 PM
  2. Unreachable statement???
    By dangolf in forum New To Java
    Replies: 5
    Last Post: 02-12-2013, 10:55 AM
  3. Replies: 2
    Last Post: 03-26-2012, 04:27 PM
  4. Strange unreachable statement error...
    By silafirion in forum New To Java
    Replies: 5
    Last Post: 12-11-2010, 05:05 AM
  5. Unreachable statement
    By lala in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 03:32 PM

Tags for this Thread

Posting Permissions

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