I am new to java. I am trying an easy game via three classes SimpleDotComGame, SimpleDotCom, GameHelper in three different .java documents all put together in a catalog dotVideo Game. SimpleDotComGame.java has the primary approach. I have actually asserted package name as
in each of these papers. SimpleDotCom.java and GameHelper.java compile without any errors. But as soon as I run SimpleDotComVideo Game.java I gain the complying with error:
Reply With Quote
Elite MemberPower Poster
SimpleDotComGame.java is trying to find a course called GameHelper as soon as the class is actually dubbed dotVideo Game.GameHelper which is why it can not discover it.Have you recompiled SimpleDotComGame.java after including the package name to the other classes.

You are watching: Java cannot find symbol class in same package

Posting code? Use code tags like this: ...Your code below... Click right here for examples of Java Code
Reply With Quote
Junior Member
Originally Posted by keang

It works without the package name bereason classes without a package name are all put in the default package and also as long as they are all in the exact same catalog they are all visible to each other. It will additionally occupational with the package name if you collection it up correctly. Can you post all the code and/or present just how you are compiling the classes and running the application and also any kind of warning or error messeras that show up for both compile and also runtime.
Posting code? Use code tags choose this: ...Your code right here... Click here for examples of Java Code
It will likewise work via the package name if you collection it up properly. Can you article all the code and/or display how you are compiling the classes and also running the app
//code for SimpleDotCompackage dotGame;public class SimpleDotCom int <> locationCells ;int numOfHits = 0;public void setLocationCells(int <> locs) locationCells = locs;public String checkYourself(String stringGuess) int guess = Integer.parseInt(stringGuess);String result = "miss";for (int cell : locationCells) if (guess == cell)outcome = "hit";numOfHits++;break;if (numOfHits == locationCells.length)outcome = "kill";System.out.println(result);return result;
//Code for GameHelper.javapackage dotGame;import java.io.* ;public class GameHelper public String getUserInput(String prompt) String inputLine = null;System.out.print (prompt + " ");tryBufferedReader is = brand-new BufferedReader(new InputStreamReader(System.in));inputLine = is.readLine();if (inputLine.length() == 0)return null;catch (IOException e)System.out.println("IOException: " +e);return inputLine;
//Code for SimpleDotComGame.javapackage dotGame;public course SimpleDotComGamepublic static void main(String<> args) int numOfGuesses = 0;GameHelper helper = brand-new GameHelper();SimpleDotCom theDotCom = new SimpleDotCom();int randomNum = (int)(Math.random() * 5);int <> areas = randomNum, randomNum+1, randomNum+2;theDotCom.setLocationCells(locations);boolean isAlive = true;while (isAlive == true)String guess = helper.getUserInput("Enter a number");String result = theDotCom.checkYourself(guess);numOfGuesses++;if (outcome.equals("kill"))isAlive = false;System.out.println("You took " + numOfGuesses + " guesses");
E:dotGame>javac SimpleDotCom.javaE:dotGame>javac GameHelper.javaE:dotGame>javac SimpleDotComVideo Game.javaSimpleDotComGame.java:8: cannot uncover symbolsymbol : course GameHelperlocation: course dotGame.SimpleDotComGame GameHelper helper = brand-new GameHelper(); ^SimpleDotComVideo Game.java:8: cannot uncover symbolsymbol : course GameHelperlocation: course dotVideo Game.SimpleDotComGame GameHelper helper = brand-new GameHelper(); ^SimpleDotComGame.java:9: cannot uncover symbolsymbol : class SimpleDotComlocation: class dotGame.SimpleDotComGame SimpleDotCom theDotCom = brand-new SimpleDotCom(); ^SimpleDotComGame.java:9: cannot discover symbolsymbol : course SimpleDotComlocation: class dotVideo Game.SimpleDotComVideo Game SimpleDotCom theDotCom = brand-new SimpleDotCom(); ^4 errors
Posting code? Use code tags like this: ...Your code below... Click right here for examples of Java Code
Posting code? Use code tags choose this: ...Your code below...

See more: Why Won T My Sim Go To Work !!, Solved: Sim Won'T Go To Work

Click right here for examples of Java Code
Quick NavigationJava ProgrammingTopSite Areasnlinux.orgVisual C++ & C++ ProgrammingC# ProgrammingVisual Basic ProgrammingWindows 8 and Later Store DevelopmentOther .NET Programming.NET FrameworkJava ProgrammingOther ProgrammingGeneral Discussionnlinux.org CommunityProgramming ProjectsSlow Chat ArchivesJobsnlinux.org Technical FAQsRetired Forum Areas
You may not article new threadsYou might not write-up repliesYou may not post attachmentsYou might not modify your posts
* The Best Reasons to Taracquire Windows 8
Learn some of the best factors why you must seriously think about bringing your Android mobile breakthrough specialization to bear on the Windows 8 platform.
Terms of Service | About Us | Privacy Notice | Contact Us | Advertise |Sitemap| The golden state - Do Not Sell My Info

Advertiser Disclosure: A few of the commodities that show up on this website are from service providers from which TechnologyAdvice receives compensation. This compensation might impact just how and also where commodities show up on this website consisting of, for example, the order in which they appear. TechnologyAdvice does not encompass all providers or all forms of commodities obtainable in the marketplace.