Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: try/catch..help needed soon as possible

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Default try/catch..help needed soon as possible

    dear all, i want a message sayin file does not exist..BEFORE it asks for the password.but wen i do that..it says variable yeet1 cannot be found..because the brackets are closing.im not that good in java.please help me.my assignment is due in 3 days.thanx alot
    import java.util.Scanner;
    import javax.swing.*;
    import java.io.*;
    public class BackItUpTxt
        public static void main(String agrs[]) throws IOException
            String D_Play = "File does not exist!";
            Scanner yeet1=new Scanner(System.in);
            System.out.println("Enter file that you want to backup:");
     catch(FileNotFoundException e){
            JOptionPane.showMessageDialog (null,D_Play);
            System.out.println("Enter password to secure your backup:");
            String yeet3=yeet1.nextLine();
                for (int count =6; count > 0 && yeet3 != "acbt"; count--)
                System.out.println("Wrong password. " + (count-1) + " attempts left.Enter password again:");

  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Thanked 329 Times in 305 Posts

    Default Re: try/catch..help needed soon as possible

    Ok, I'm confused with your code. Why do you ask for the password to the backup when FileNotFound Exception is thrown? Also, the reason yeet1 cant be found is because of scope.
    Scanner yeet1=new Scanner(System.in);
    This is in your try statement. However, you are trying to use this variable in your catch statement:
    String yeet3=yeet1.nextLine();
    That cannot be done. Either you need to declare yeet1 before the try/catch statement (and you can still initialize it inside the try statement), or you have to recreate the yeet1 variable inside the catch statement.

Similar Threads

  1. how do i try/catch this?
    By safra in forum Exceptions
    Replies: 6
    Last Post: October 29th, 2011, 11:14 AM
  2. (while) insted of (try and catch)
    By b109 in forum Java Theory & Questions
    Replies: 6
    Last Post: May 13th, 2010, 09:01 PM
  3. help needed
    By The Lost Plot in forum Loops & Control Statements
    Replies: 4
    Last Post: March 16th, 2010, 03:55 AM
  4. catch all
    By silverspoon34 in forum Exceptions
    Replies: 1
    Last Post: November 29th, 2009, 02:18 PM
  5. try/catch
    By rsala004 in forum Exceptions
    Replies: 5
    Last Post: July 19th, 2009, 03:20 PM