Hey guys. I'm trying to use a small jar file I made in my program as an API type external. But now I'm stuck. How the hell do I import this thing? I've added the "Required Libraries" into JCreator LE, and still errors, but I have no idea where I'm supposed to be looking to get help on this. :\
20 Replies - 502 Views - Last Post: 30 May 2012 - 08:48 PM
Replies To: Using external Jar.
#2
Re: Using external Jar.
Posted 30 May 2012 - 06:42 PM
Can you show us where you placed the jar file and your directory structure? Usually adding a jar to your program just involves adding it to a lib folder or the classpath. What error are you encountering anyway?
#3
Re: Using external Jar.
Posted 30 May 2012 - 06:53 PM
I added the .jar file to
And my error is just "Cannot find symbol".
Project -> Project Settings -> Required Libraries
And my error is just "Cannot find symbol".
#4
Re: Using external Jar.
Posted 30 May 2012 - 07:17 PM
This keeps getting vaguer and vaguer. Could you at least post the whole stack trace if you're unwilling to post some code?
#5
Re: Using external Jar.
Posted 30 May 2012 - 07:19 PM
Literally my code is
And my exact error is
My Api.Print class is
public class Main {
public static void main(String[] args) {
println("Hello World!");
}
}
And my exact error is
C:\Users\Nathan\Documents\Programming\Java\Sup\Main.java:6: error: cannot find symbol
println("Hello World!");
^
symbol: method println(String)
location: class Main
My Api.Print class is
public class Print {
public void println(String str) {
System.out.println(str);
}
public void print(String str) {
System.out.print(str);
}
public void error(String str, String err) {
System.out.println(str + ": " + err);
}
}
#6
Re: Using external Jar.
Posted 30 May 2012 - 07:46 PM
Oh, where is the import to your class of Print in your main class? You might have placed your jar correctly but it will not access your libraries without an import. And by the way, your class is named "Main", which is a bad idea, why not try renaming it to something other than a Java reserved word? Even if it's capitalized it might still cause some problems, programmatical or human - made.
#7
Re: Using external Jar.
Posted 30 May 2012 - 07:50 PM
This thread is just about asking how I would go about importing the class..?
#8
Re: Using external Jar.
Posted 30 May 2012 - 07:56 PM
Were are April the 1st or what ? Has nothing to do witj Jar. Your code simply does not compile.
You need a Print object to be able to call its println() method
You need a Print object to be able to call its println() method
public static void main(String[] args) {
Print p = new Print();
p.println("foo");
}
#9
Re: Using external Jar.
Posted 30 May 2012 - 07:59 PM
WWhile this can solve my problem, is it possible to do it without creating a Print object?
#10
Re: Using external Jar.
Posted 30 May 2012 - 08:01 PM
If println() is not static, you need a Print object to access it
If println() was static you could just: Print.println() without instantiating Print.
Again what is the relation with jar ?
If println() was static you could just: Print.println() without instantiating Print.
Again what is the relation with jar ?
#11
Re: Using external Jar.
Posted 30 May 2012 - 08:05 PM
What do you mean by what is the relation? What I want to be able to do.is just use it like
println("hello world")
#12
Re: Using external Jar.
Posted 30 May 2012 - 08:08 PM
I can't beleive that after 259 posts and a few +1 you still don't know that you need to instantiate an object before being able to call one of its methods !!! You are drunk or what ?
#13
Re: Using external Jar.
Posted 30 May 2012 - 08:14 PM
No, unfortunately my girlfriend doesn't let me drink while our son is awake.
And after using programs like PowerBot which uses imports from its jar client, which doesn't need objects to be created, I thought it would be possible to do it myself, apparently not.
And after using programs like PowerBot which uses imports from its jar client, which doesn't need objects to be created, I thought it would be possible to do it myself, apparently not.
#14
Re: Using external Jar.
Posted 30 May 2012 - 08:19 PM
Come on ... you are the one who wrote that code:
http://www.dreaminco...1&#entry1625570
http://www.dreaminco...1&#entry1625570
public class NameListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String fname = "";
String lname = "";
// you need a Scanner object
Scanner nameScan = new Scanner(_name.getText());
// to be able to invoke its .hasNext() and next() methods
while(nameScan.hasNext()) {
fname = nameScan.next();
lname = nameScan.next();
}
// you need a FileWriter object
FileWriter fw = new FileWriter("users.txt", true);
int id = Integer.parseInt(_id.getText());
String name = _name.getText();
...
// to access its write() method
fw.write(id + " " + name + " " + username + " " + password + " " + position + "\n");
#15
Re: Using external Jar.
Posted 30 May 2012 - 08:22 PM
|
|

New Topic/Question
Reply



MultiQuote





|