2

I am using alchemy API for my project. I downloaded java sdk from alchemyapi and tried to run one example code.

It is compiling without any error but when i try to run it it is showing error (error msg:Could not find or load main class) I have set the CLASSPATH by including the dot(.) and the jar files which is available for these api but it is still showing error.I have tried all the option for setting the class path.

vin
  • 231
  • 1
  • 17
  • Please give more details, like the command that you actually run. You see: messages don't lie. If you are told that the JVM can't find your classes, then surprise, the classpath that your are giving to the JVM must be incomplete. It is as simple as that. – GhostCat Jul 19 '16 at 09:31
  • I feel like this has more to do with package declaration and incorrect directory structure, since I'm assuming you wrote the main class yourself? – Jorn Vernee Jul 19 '16 at 09:35
  • .;C:\Users\Vin\java\java-sdk-3.0.1-jar-with-dependencies.jar this is the classpath my file is present in /vin/java/ directory. i didn't write any thing i just copied the example code from the sdk and tried to run it. – vin Jul 19 '16 at 09:39
  • And what is the command you're using?, What is the package of the main class? And from which directory are you running the command? [These are all important](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html) – Jorn Vernee Jul 19 '16 at 09:43
  • I am using java GetNewsDocumentexample command to run it. and the package of main class is package com.ibm.watson.developer_cloud.alchemy_data_news.v1; and i am compiling it from /vin/java/ i have checked all these links which are available for setting the path and classpath – vin Jul 19 '16 at 09:46
  • Well, that link explains exactly what's going wrong here: _"Java classes are organized into packages which are mapped to directories in the file system."_ and _"suppose you want the Java runtime to find a class named Cool.class in the package utility.myapp. If the path to that directory is C:\java\MyClasses\utility\myapp, you would set the class path so that it contains C:\java\MyClasses."_ I.e. you're missing the relevant directory structure. In your case though, it will _probably_ be sufficient to remove the package declaration. – Jorn Vernee Jul 19 '16 at 09:58
  • Thank you so much Jorn. It is working now....:) – vin Jul 19 '16 at 10:09

1 Answers1

0

What you have to do is to remove the package name from the class.Because the package name is already there in your jar which you have imported.

jiwitesh
  • 123
  • 1
  • 10