Solved

java error:  can't find symbol

Posted on 2014-02-26
7
406 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 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
Independent Software Vendors: 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!

 
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

Technology Partners: 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

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

749 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