Results 1 to 6 of 6
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Java doesn't understand what .exists() is?

    For some odd reason Java won't recognize ".exists()" now. Despite doing it for me before and not caring.

    So I have this void basically saying "if kit serial numbers file doesn't exist"

    I put static string fileName there in order to make Java happy

    Java Code:
    static  String fileName = "Kit Serial Numbers TEMPLATE.csv";
       
            private static void readString() throws FileNotFoundException{
                
               
                if(fileName.exists() != true){
                    
                }
    }

    then I have the actual working instance of this over here on line 6
    Java Code:
    String stuff = jComboBox2.getSelectedItem().toString();
         
         File happyFile = new File("z:\\EvansInterface_Beta\\"+stuff+".csv");
        try {
            if(stuff!="-----"){ // so the user can't screw up and make -----.csv by accident
                if(happyFile.exists() != true){  //if happyFile doesn't exist create a file with a template
                FileWriter fileWriter = new FileWriter(happyFile, true); 
                BufferedWriter buffer = new BufferedWriter(fileWriter);
                PrintWriter printWriter = new PrintWriter(fileWriter);
                printWriter.printf( "%s\n,%s,,,,,,,%s,,,,%s\n,%s,%s,%s,,,,%s,%s,%s,%s,,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",stringthing,name1,name2,name3,Serial,assembly,part,anode,cathode,header,tantalum,Cap,ESR,Leakage,Assemblylotselected,Anode1,Anode2,Anode3,Anode4,Anode5,Cathodelot,TeflonSpacer1,TeflonSpacer2,TeflonSpacer3,HeaderGlass,Tantalumlot,Teflon,Comments);
                printWriter.close();         
        
                                             }  
                
                
                  System.out.println("I refuse");
                }
                
                else{
                     
                    System.out.println("else");
                 }
        } catch (IOException ex) {
            Logger.getLogger(mainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        }

    What am I doing in the bottom one that I'm not doing in the top one? Also, I made sure both have the same imports, so it's NOT a problem with imports
    Last edited by innovo; 08-14-2015 at 07:45 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Java doesn't understand what .exists() is?

    Java won't recognize ".exists()"
    Please copy the full text of the error message and paste it here.
    You need to look at the API doc to see what methods each class has available. There are some classes that have an exists() method and many classes that do not have an exists() method.
    Note: fileName is a String object and happyFile is a File object.

    One way to see what classes have a method is to use the INDEX link at the top of the API doc page.
    Click on that link to get a list of all the methods. Then click on the first letter in the list of letters from A to Z that is across the page near the top to see all the methods whose name starts with that letter.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Re: Java doesn't understand what .exists() is?

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it here.
    You need to look at the API doc to see what methods each class has available. There are some classes that have an exists() method and many classes that do not have an exists() method.
    Note: fileName is a String object and happyFile is a File object.

    One way to see what classes have a method is to use the INDEX link at the top of the API doc page.
    Click on that link to get a list of all the methods. Then click on the first letter in the list of letters from A to Z that is across the page near the top to see all the methods whose name starts with that letter.
    Created dir: /Users/me/NetBeansProjects/EvansInterface/build/classes
    Created dir: /Users/me/NetBeansProjects/EvansInterface/build/empty
    Created dir: /Users/me/NetBeansProjects/EvansInterface/build/generated-sources/ap-source-output
    Compiling 14 source files to /Users/me/NetBeansProjects/EvansInterface/build/classes
    /Users/me/NetBeansProjects/EvansInterface/src/evansinterface/CsvFileReader.java:72: error: cannot find symbol
    if(fileName.exists() != true){
    symbol: method exists()
    location: variable fileName of type String
    Note: /Users/me/NetBeansProjects/EvansInterface/src/evansinterface/mainWindow.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    /Users/me/NetBeansProjects/EvansInterface/nbproject/build-impl.xml:948: The following error occurred while executing this line:
    /Users/me/NetBeansProjects/EvansInterface/nbproject/build-impl.xml:288: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Java doesn't understand what .exists() is?

    Please learn to properly format your code so it is readable. Even if you use the code tags, you may need to correct the indentation. You should use equals() and not != or == to compare strings. See line 5 above. I also suggest you get rid of the printwriter and file writer stuff and just focus on the file existence problem. You can print informative messages if it exists or doesn't. And you can always create the file manually using your favorite OS utility to aid in debugging.

    Now that I have suggested some debugging guidelines, I can tell you that exists() is a method of the File class and not the String class.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Java doesn't understand what .exists() is?

    error: cannot find symbol
    if(fileName.exists() != true){
    symbol: method exists()
    location: variable fileName of type String
    That says the compiler can not find the method: exists() defined for the class String.

    See post#2
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default Re: Java doesn't understand what .exists() is?

    Quote Originally Posted by Norm View Post
    That says the compiler can not find the method: exists() defined for the class String.

    See post#2
    I eventually got it, it was as you said "Note: fileName is a String object and happyFile is a File object." Upon changing this I had no problems

Similar Threads

  1. Replies: 13
    Last Post: 10-04-2012, 07:45 PM
  2. Replies: 9
    Last Post: 08-10-2012, 03:48 PM
  3. Java noob doesn't understand importing
    By Javanoobguy in forum New To Java
    Replies: 1
    Last Post: 04-05-2012, 11:35 PM
  4. Replies: 3
    Last Post: 05-29-2011, 08:40 PM
  5. Replies: 5
    Last Post: 02-11-2011, 08:33 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
  •