0

I have already come across this error. I couldn't figure out today also.

   package com.example.cassandra;

   public class test
   {
     public static void main(String[] a)
     { 
        System.out.println("test");
     }
   }

This is my java file. My working directory is

  com/example/cassandra

Compile command is

  javac test.java

Changed working directory to parent directory of com

  cd ../../..

Run command

  java test

Says

  could not find or load main class test

Any body please explain what's the problem here?

Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • Not conflicting, look carefully at the command lines they run along with their current directories and package names, and on your machine, `cd` to the parent of `com` and try running this command. – nanofarad Feb 25 '15 at 11:36
  • you have missed static keyword in main() functions definition – V__ Feb 25 '15 at 11:37

1 Answers1

0

You will need to actually specify the package name:

java com.example.cassandra.test
nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • @GopsAB Not conflicting, look carefully at the command lines they run along with their current directories and package names, and on your machine, `cd` to the parent of `com` and try running this command. They're running it inside the package folder, which is wrong. – nanofarad Feb 25 '15 at 11:36
  • @GopsAB Just try it and see. – nanofarad Feb 25 '15 at 11:37
  • @GopsAB: No conflict at all - in the answer there, the OP was advised to run `java test.test` which is again the fully-qualified classname. – Jon Skeet Feb 25 '15 at 11:37
  • @hexafraction thanks. `Exception in thread "main" java.lang.NoClassDefFoundError: com/example/cassandra/test (wrong name: org/example/cassandra/test) at java.lang.ClassLoader.defineClass1(Native Method)` I tried the suggested one here and i got this error. But test.class is present in the specified directory – Gibbs Feb 25 '15 at 11:39