Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Error: Could not find or load main class ScannerClassInput

  1. #1
    Junior Member
    Join Date
    Feb 2023
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Error: Could not find or load main class ScannerClassInput

     
    package com.DataFlair.StringInput;
    import java.util.*;
    import java.util.Scanner;
    public class ScannerClassInput
    {
        public static void main(String args[])
        {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter a String");
            String str = sc.nextLine();
            System.out.println("The String input using Scanner class is: " +str);
        }
    }

    Error
    C:\Users\nandhu\OneDrive\Documents\NetBeansProject s>java ScannerClassInput
    Error: Could not find or load main class ScannerClassInput
    Caused by: java.lang.NoClassDefFoundError: com/DataFlair/StringInput/ScannerClassInput (wrong name: ScannerClassInput)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error: Could not find or load main class ScannerClassInput

    The java command takes the complete name of the class which includes the package name:
    java com.DataFlair.StringInput.ScannerClassInput
    The java command needs to be entered in the directory that contains the path: com/DataFlair/StringInput/
    The path is used to find the ScannerClassInput.class file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    nandhutee (February 23rd, 2023)

Similar Threads

  1. Replies: 6
    Last Post: August 22nd, 2014, 04:16 PM
  2. Error: Could not find or load main class Program, I need help
    By tsuisou in forum Java Theory & Questions
    Replies: 5
    Last Post: August 22nd, 2014, 03:54 PM
  3. Error: Could not find or load main class
    By ARULARASAN in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2013, 03:46 PM
  4. Error: Could not find or load main class
    By lijepdan in forum Java Theory & Questions
    Replies: 8
    Last Post: March 22nd, 2013, 04:32 PM
  5. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 11:40 PM