0

I created simple java project by using Intellij and it works in both command prompt and intellij as well. here is the code:

public class HelloWorld {
    public static void main(String[]args){

        System.out.println("Hello World!");
    }
}

Then I created a package and moved main class into it and it works in intellij but not in command prompt.my codes are,

package com.attempt;

public class HelloWorld {
    public static void main(String[]args){

        System.out.println("Hello World!");
    }
}

this is what appears in command prompt:


>  Directory of
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt
> 
> 03/31/2020  10:07 PM    <DIR>          . 03/31/2020  10:07 PM    <DIR>
> .. 03/31/2020  11:57 PM               438 HelloWorld.class 03/31/2020 
> 10:06 PM               152 HelloWorld.java
>                2 File(s)            590 bytes
>                2 Dir(s)  408,375,992,320 bytes free
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>javac
> HelloWorld.java
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>java
> HelloWorld Error: Could not find or load main class HelloWorld Caused
> by: java.lang.ClassNotFoundException: HelloWorld
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>

this how they stored

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
dylanMj
  • 11
  • 1
  • 1
    Please read the answers in the duplicate which pretty much answer this problem in depth. Also, please have a look at the [ask] and the [help] to see how to better use this site. For instance, your question title should summarize your problem, not your ability status. You should search on the problem before asking and show the concrete results of those efforts in your question. – Hovercraft Full Of Eels Mar 31 '20 at 19:08
  • please do a proper research before asking a question – iamnabink Mar 31 '20 at 19:11
  • 1
    For example, [this general Google search](https://www.google.com/search?q=java+classnotfoundexception) and [this Stack Overflow site-specific search](https://www.google.com/search?q=java+classnotfoundexception+site:stackoverflow.com) should get you well started at taking a stab at solving this. – Hovercraft Full Of Eels Mar 31 '20 at 19:11

0 Answers0