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
Solved

java error:  can't find symbol

Posted on 2014-02-26
7
402 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SequenceInputStream example 3 19
Bot application - advice 3 38
Eclipse for Java EE development 2 27
restrict decimal places for double datatype 10 19
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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