• Post Reply Bookmark Topic Watch Topic
  • New Topic

How To access method from different class  RSS feed

 
Rahul B. Shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,
I Have 2 Different . java files in same package beerselection i.e BeerExpert.java & SelectBeer.java
Both Classes Have public access,
BeerExpert.java contains public method called getBrands();
I Am Calling Above Method In SelectBeer.java As
BeerExpert be = null; & then
be = new BeerExpert();
It Says Could Not Find Symbol....
I Have Check Spellings & There Are no mistakes
I Am Not Getting What Is Wrong
Thank You
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul, welcome to Ranch family.

Best is to use some IDE. I created a poll for best IDE(s) on my blog the other day.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul, welcome to the Ranch.

If you're a beginner with Java, I disagree about starting to use an IDE right away. It's better to learn the basics first, and concentrate on learning Java, instead of trying to learn Java and the IDE at the same time. It's better to start with a simple text editor. Notepad++ is a good and free text editor that has syntax highlighting for Java. When you're comfortable with the basics of Java, and know how to compile your source files on the command line, then it's time to have a look at IDEs.

Can you show us what your code looks like?

Note that in Java, your source file must have the same name as the public class or interface that you define in your source file. So if your public class is called BeerExpert, it must be in a file called BeerExpert.java. Java is case sensitive, so BeerExpert is not the same as beerExpert or Beerexpert.

How is your classpath set? Do you have a CLASSPATH environment variable set? If yes, then remove it - it's best to leave the CLASSPATH environment variable not set.
 
Rahul B. Shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




I Have Set ClassPath & is'nt that useful ,So that We can run java programmes from anywhere ??
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would still say to use IDE along with Notepad.
Using IDE is not a big task and you will only learn it while trying to overcome those compilation/running issues.
Otherwise you will have to again come to the issues you faced while using compilation and the fact is that once you start using IDE's, you will forget how you compiled your code from command line and will always need to refer the docs.

Anyway, compiling your code from command line does give me "Symbol not found errors" and all of those are related to Servlet.jar being not present in the classpath.

Can you recheck that servlet.jar/j2ee.jar is present in your classpath or you can post the exact symbol which was not found at your end...

One more thing, use the code tags when you post, it gives the feeling of IDE....
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when you post source code. I have added them to your post above for you.

You didn't say earlier that you were creating a servlet. What application server are you using to run that servlet (Apache Tomcat? Glassfish? Something else?).

What commands are you entering to compile and run this, and what is the exact error message that you get (copy and paste the error message)?

Did you combine both classes, and do you have BeerExpert.class and SelectBeer.class in the same directory? Is the structure of your web application correct?
 
Rahul B. Shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
When I Tried In Eclipse It Worked
Thank - You For Help
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you were trying to compile in wrong way.

Good stick to IDE. You may need commands for writing ANT buildfile in future but rarely need to compile from command line.

Eclipse is the most voted IDE in the poll at my blog.

All the best.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny Bhandari wrote:I would still say to use IDE along with Notepad. . . .
I would say that using Notepad along with an IDE makes your advice even worse than it was at first.
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Sunny Bhandari wrote:I would still say to use IDE along with Notepad. . . .
I would say that using Notepad along with an IDE makes your advice even worse than it was at first.


Well that was considering the advice given by Jesper de Jong in one post above my post..
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny Bhandari wrote: . . . Well that was considering the advice given by Jesper de Jong in one post above my post..
No, Jesper said to use Notepad++. Something totally different. And I still agree with him, it is best to avoid IDEs at the beginning stage.
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Sunny Bhandari wrote: . . . Well that was considering the advice given by Jesper de Jong in one post above my post..
No, Jesper said to use Notepad++. Something totally different. And I still agree with him, it is best to avoid IDEs at the beginning stage.


But Rahul finally resolved it using IDE. The debate continues....
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunny Bhandari wrote:. . . The debate continues....
No, it doesn't.

I think we should shut up about IDEs, in this discussion at least.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!