Solved

Problem to call the event

Posted on 2015-02-05
21
183 Views
Last Modified: 2015-02-10
Hi,
How to to resolve this

Description	Resource	Path	Location	Type
CalCl cannot be resolved to a type	CalCl3.java	/JLib3/src/CalCl3	line 3	Java Problem

Open in new window


using these codes?

package CalCl3;
import JLib2.Calcl;

public class CalCl3 implements CalCl {

}

Open in new window


while CalCl does exists within the another Java project, that is
https://dl.dropboxusercontent.com/u/40211031/JLib2.zip
0
Comment
Question by:HuaMinChen
[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
  • 11
  • 9
21 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 40592995
Do you have that JLib2.jar in the classpath for the JLib3 project? Otherwise the compiler won't know anything about it.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40593001
Yes, I did add this jar to JLib3 project.
0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40593027
If the .jar file is in the .zip file, get the .zip file on your machine and unzip it.
Then add the .jar file to your classpath.
If you run from the command line, something like:
java -cp ./JLib2.jar  CalC13

Open in new window

0
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
LVL 11

Author Comment

by:HuaMinChen
ID: 40593124
Sorry, I did add the jar file to JLib3. Can you please advise what is wrong inside it attached below?
https://dl.dropboxusercontent.com/u/40211031/JLib3.zip
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40593125
I am using Eclipse.
0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40593939
In Eclipse, did you add it to your project?

If not, right-click the project and select Build Path / Add External Archives..., then select your .jar file.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40595022
I already attach jar file to the project (see the attached)
t966.png
0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40595046
In your import statement, do not use the jar file name.
Instead use the package name for the class followed by the class name.
For example, if you want to use the TimeUnit class from the standard java library, the import statement is:
import java.util.concurrent.TimeUnit

The package name, java.util.concurrent, is followed by the class name, TimeUnit
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40595281
Thanks. I try to use package name instead
package CalCl3;
import CalCl.CalCl;

public class CalCl3 implements CalCl {

}

Open in new window


but I still get this
Description	Resource	Path	Location	Type
The type CalCl cannot be a superinterface of CalCl3; a superinterface must be an interface	CalCl3.java	/JLib3/src/CalCl3	line 4	Java Problem

Open in new window

0
 
LVL 13

Assisted Solution

by:Mark Bullock
Mark Bullock earned 500 total points
ID: 40595696
When you use the "implements" keyword, that means CalCl must be an abstract class.

If it is not an abstract class, then use the "extends" keyword. Then CalCl3 would be a subclass of CalCl.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40596610
Many many thanks. One last thing, to these codes

package CalCl3;
import CalCl.CalCl;

public class CalCl3 extends CalCl {
	System.out.println(Float.toString(computePayment(4000,0.5,3000,4)));
}

Open in new window


how to correct these problems?

Description	Resource	Path	Location	Type
Return type for the method is missing	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error on token "println", invalid AnnotationName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error on tokens, delete these tokens	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ";" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ";" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MemberValue	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "}" to complete ClassBody	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "Identifier (" to complete MethodHeaderName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "Identifier (" to complete MethodHeaderName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "SimpleName" to complete QualifiedName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem

Open in new window

0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40597406
Ni hao ma wo de pengyou.

Line 5 should be inside a method which must have a return type (void if you don't return anything).
If you don't already have a main method, add one like this inside your CalCl3 class:
    public static void main(String[] args) {
        System.out.println(Float.toString(computePayment(4000,0.5,3000,4)));
    }

Open in new window

0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40597603
Mark,
You're very nice! And do you expect to talk in Mandarin?

I still get these
Description	Resource	Path	Location	Type
Return type for the method is missing	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error on token "println", invalid AnnotationName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error on tokens, delete these tokens	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ";" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ";" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MemberValue	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert ")" to complete MethodDeclaration	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "}" to complete ClassBody	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "Identifier (" to complete MethodHeaderName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "Identifier (" to complete MethodHeaderName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem
Syntax error, insert "SimpleName" to complete QualifiedName	CalCl3.java	/JLib3/src/CalCl3	line 5	Java Problem

Open in new window


to these codes.
package CalCl3;
import CalCl.CalCl;

public class CalCl3 extends CalCl {
	public static void main(String[] args) {
        System.out.println(Float.toString(computePayment(4000,0.5,3000,4)));
    }
}

Open in new window

0
 
LVL 13

Assisted Solution

by:Mark Bullock
Mark Bullock earned 500 total points
ID: 40597737
I just speak enough Mandarin to make people laugh.

Does you computePayment method return a float? I assume it's defined in the CalCl class. It should return float if you're going to cast it to Float.

I can't reproduce the problem since I don't have your .jar file.

You are using Eclipse, so you can click on the light bulb icon at the beginning of the statement with the syntax error. It will often suggest a way to fix the problem and you can click on it to make the change.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40597763
Many thanks Mark.
I now only get this

Description	Resource	Path	Location	Type
Cannot make a static reference to the non-static method computePayment(double, double, double, int) from the type CalCl	CalCl3.java	/JLib3/src/CalCl3	line 6	Java Problem

Open in new window

to these codes.

package CalCl3;
import CalCl.CalCl;

public class CalCl3 extends CalCl {
	public static void main(String[] args) {
        System.out.println(Double.toString(computePayment(4000,0.5,3000,4)));
    }
}

Open in new window

Here is JLib2 project
https://dl.dropboxusercontent.com/u/40211031/JLib2.zip

inside which jar file also included.
0
 
LVL 13

Accepted Solution

by:
Mark Bullock earned 500 total points
ID: 40598624
You can either
1. make the CalCl class static by changing public class CalCl to public static class CalCl, or
2. create an object of type CalCl, then call the payment method like this:
CalCl calc = new CalCl;
double payment = calc.computePayment(4000,0.5,3000,4)
System.out.println(Double.toString(payment));
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40599875
Many thanks Mark.
I get these problem

Description	Resource	Path	Location	Type
Illegal modifier for the class CalCl; only public, abstract & final are permitted	CalCl.java	/JLib2/src/CalCl	line 3	Java Problem
Syntax error, insert ";" to complete LocalVariableDeclarationStatement	CalCl3.java	/JLib3/src/CalCl3	line 7	Java Problem

Open in new window


to declare it as static

package CalCl;

public static class CalCl {
    
	public double computePayment(
            double loanAmt,
            double rate,
            double futureValue,
            int numPeriods) {
		double interest = rate / 100.0;
		double partial1 = Math.pow((1 + interest), 
		              - numPeriods);
		double denominator = (1 - partial1) / interest;
		double answer = (-loanAmt / denominator)
		              - ((futureValue * partial1) / denominator);
		return answer;
	}
}

Open in new window

0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40599992
If the class is static, the method must be static also. Add the static keyword to the computePayment class.

The other option is #2 from my previous comment.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40599996
Sorry, I still get this

Description	Resource	Path	Location	Type
Illegal modifier for the class CalCl; only public, abstract & final are permitted	CalCl.java	/JLib2/src/CalCl	line 3	Java Problem

Open in new window


to these

package CalCl;

public static class CalCl {
    
	public static double computePayment(
            double loanAmt,
            double rate,
            double futureValue,
            int numPeriods) {
		double interest = rate / 100.0;
		double partial1 = Math.pow((1 + interest), 
		              - numPeriods);
		double denominator = (1 - partial1) / interest;
		double answer = (-loanAmt / denominator)
		              - ((futureValue * partial1) / denominator);
		return answer;
	}
}

Open in new window

0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40600174
Use option 2.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40600177
How to correct the problem now, to JLib2, that is giving the jar file?
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

635 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