0

So I have two Jars I want to use in my project from here http://www.jhlabs.com/ip/filters/index.html

I added both CheckFilter and MarbleFilter to my class path. But when I do

CheckFilter();

It says I have to create a method CheckFilter()

I'm pretty sure that's the method I need to call to use that effect. But when I try any of the other methods in the library Jar it still gives me the same thing.

I have no experience with importing/using external libraries. Any help would be great.

checkFilter = new CheckFilter();
   CheckFilter();

I tried above and it says I need to create a local variable checkFilter

SolidCloudinc
  • 329
  • 10
  • 27
  • 1
    Have you imported the file into your Workspace? Have you `#imported`? – nhgrif Nov 20 '13 at 18:52
  • A method belongs to a class. If it's static, you need to call TheClassName.theMethod(). If it isn't static, you need to have an instance of the class, and call the method on this instance. Read an introductory Java book or the first section of the Java tutorial. – JB Nizet Nov 20 '13 at 18:53
  • Please link us to the JavaDoc/api of `CheckFilter`. – Daniel Kaplan Nov 20 '13 at 18:54
  • Yes it's been imported and http://www.jhlabs.com/ip/filters/download.html – SolidCloudinc Nov 20 '13 at 18:57

5 Answers5

2

How are you writing up the code. I will suggest to use eclipse IDE, it will make your tasks simple

If you are using eclipse. You need to do import the jar Filters.jar to your build path

which as you mentioned you downloaded from JHLabs Download page

I found Filters.jar inside dist directory.

Then you will be able to import the class or package

import com.jhlabs.image.*;

OR

import com.jhlabs.image.CheckFilter;

After importing the class or package you will be able to create object to it by

CheckFilter checkFilter = new CheckFilter();

In case you are totally new you can take help from people over IRC or chat and get going.

Someone would be able to quickly help you out

----==----==----==----==----==----==----==----==---- Read your comments and Question again.

You are totally missing the point. If you call to CheckFilter() directly without invoking new keyword, compiler will consider you are trying to access a method which is inside the class you are writing up. and give you error.

As I mentioned above. Your are trying to accessing Instance variable for the class without declaring it. Either do CheckFilter checkFilter;

before you access checkFilter variable or directly instantiate the class the way I mentioned.

Seems to me you are missing a log of points :D

Acewin
  • 1,657
  • 4
  • 17
  • 36
1

Methods don't exist without a class. That is probably the constructor to a class. Use

CheckFilter checkFilter = new CheckFilter();

instead. Then call methods on checkFilter.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • 2
    Is `CheckFilter` a class or a method? Seems like you're missing some java fundementals. You should probably read a tutorial. Anyway, you need to define the variable's type on the right hand side. – Daniel Kaplan Nov 20 '13 at 18:55
  • @SolidCloudinc I just edited the spacing of this answer to clarify exactly what you should be typing, as your comment seems to suggest you're doing it wrong. Please check the current answer. – nhgrif Nov 20 '13 at 18:57
  • @SolidCloudinc I'd like to echo many users' suggestions here for you to read some tutorials on Java. You needed to declare a new object of type `CheckFilter` with name `checkFilter` by calling the constructor `CheckFilter()`, which requires the keyword `new`. None of this should be confusing or new. – SimplyPanda Nov 20 '13 at 19:05
0

From @andy-thomas in this similar question

The import statement imports classes from the jar file, not the jar file itself.

An import statement of the form:

import stdlib.*;

will import all the classes in the package stdlib.

Oracle provides this tutorial on importing.

Community
  • 1
  • 1
zacatac
  • 69
  • 3
0

This statement

CheckFilter();

Tries to call a method CheckFilter defined in your class, which is not the case. If this is a utility function, this may be a static method, in which case you can call it like this

ClassName.CheckFilter();   // replace ClassName with the class containing this function

If not, then you may have to instantiate an object

ClassName obj = new ClassName();
obj.CheckFilter();

or skip the object variable

new ClassName().CheckFilter();   // Not prefered

To add jar files, right click on your project in "Package Explorer", go to "Configure Build Path" and then to "Add External Jars".

Ankit Rustagi
  • 5,539
  • 12
  • 39
  • 70
0

Set the jar (libraries) into your classpath and use import statements in your java code to include the required Classes.

nashter
  • 1,181
  • 1
  • 15
  • 33