Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java error:  can't find symbol

Posted on 2014-02-26
7
Medium Priority
?
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 36

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

722 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