Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:11:10+00:00 2026-06-18T12:11:10+00:00

I have a class set to return a string like so: package TextRPG; public

  • 0

I have a class set to return a string like so:

package TextRPG;

public class File {

    static String file;

    public static void setFile(String fileLocation) {
        file = fileLocation;
    }

    public static String getFile(){
        return file;
    }
}

But when i try to call it like so:
PrintWriter save = new PrintWriter(File.getFile());
I get an Error. What am I doing wrong?
EDIT, the netbeans error is :
cannot find symbol
symbol: method getFile()
location: class File

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:11:10+00:00Added an answer on June 18, 2026 at 12:11 pm

    You have shot yourself in the foot because you are ignoring the Java naming conventions.

    Variable names should start with a lowercase letter. Thus:

    package textrpg;
    
    public class File {
        static String file;
    
        public static void setFile(String fileLocation) {
            file = fileLocation;
        }
    
        public static String getFile(){
            return file;
        }
    }
    

    The java compiler doesn’t care about this … but your foot shot happened because you declared a field called File in a class called File, and Java’s rules for disambiguating the name collision came up with a strange answer.

    (If you included the compiler error message, it would be easier to explain …)


    There are a couple of other problems with this class:

    • The is very non-OO code. You have a static field and static methods for getting and setting it. This kind of thing is a bit “icky” … and will lead to problems if you need to reuse the code in another context, or implement unit tests, etcetera.

    • You are using the same name as a well-known standard class (java.io.File). This could lead to problems later on if some other class in your application needs to use both java.io.File and textrpg.File.

    • You are also ignoring the convention about how to form a package name that is designed to avoid package name collisions.


    Before you write more code, I strongly recommend that you read the Sun Java Coding Conventions. And unless you have a really really good reason not to, follow them. (“I couldn’t be bothered” is NOT a good reason, IMO.)


    Ah. So the compilation error is in this:

    PrintWriter save = new PrintWriter(File.getFile());
    

    and it is saying that it can’t find a method called getFile() in File.

    Without seeing the rest of that class, I can’t be sure. However, I suspect that you are importing java.io.* … and THAT means that the File in the code snippet will be referring to java.io.File … which doesn’t have a getFile() method!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have class like below class Person { public string Name{get;set;} public string Surname{get;set;}
In C#, I have a class set up like so: class Page { public
Say I have a class that looks like this (get/set omited): class InfoClass{ String
Suppose I have: class Foo { public String Bar { get; set; } }
I have class like the following: class test { public string Name; public string
I have made a class Location which looks like this: package TruckingCompany; public class
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field
I have a class say public class CostStore { int DirectorateId { get; set;
Assumptions Suppose I have a class with a property: class ClassWithProperty { public string
Okay, let's say we have a class defined like public class TestClass { private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.