Solved

java error:  can't find symbol

Posted on 2014-02-26
7
393 Views
Last Modified: 2014-02-27
I have a problem.  I don't understand how to use a constructor with an instance class.  I created the math classes and set up a demo class but the specific stub doesn't work with factorial class and I get the error can't find the symbol factorial.  Are the classes formulated correctly and if not what do I need to do to have the factorial class recognized? I am new to java and trying to catch up in a class about it.  mathclass.java
0
Comment
Question by:tangocoder
  • 5
7 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 39891164
Replace
factorial afact = new factorial(num);

Open in new window

by
factorial afact = MyMath.factorial(num);

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 39891166
>>  what do I need to do to have the factorial class recognized?
factorial is not a class. MyMath is a class (containing only static methods)
To call a static method of a class you write

<ClassName>.<method name>(<method parameters if any>)
0
 
LVL 1

Author Comment

by:tangocoder
ID: 39891207
Now the problem is that factorial in TestMyMath class is giving can't find symbol error.  How do I initialize factorial to be defined in this class?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 37

Expert Comment

by:zzynx
ID: 39891227
By importing your MyMath class, the way you imported the JOptionPane class by writing:
import javax.swing.JOptionPane;

Open in new window


So, you should write somehting like:

import <path of your MyMath class>.MyMath;

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 39891241
Normally each of your classes has as a first line something like:

package com.MyFirm.whatever;

If both your MyMath class and your TestMyMath class are in the same package (and have the same package line, that import is not needed since they "see" each other)

If the MyMath class is in another package, you have to tell your TestMyMath class in which package it has to look to find the MyMath class via that import instruction.

Some explanation about packages: http://www.tutorialspoint.com/java/java_packages.htm
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39891670
Can you post your updated code? And post each .java file separately and exactly as you have it.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 39894149
Thanx 4 axxepting
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now