Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1047673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:20:18+00:00 2026-05-16T16:20:18+00:00

Hey, this is probably a simple question, but I am having trouble running my

  • 0

Hey, this is probably a simple question, but I am having trouble running my java program from command line. I have 3 java files that I compiled and now I have 3 class files in a directory. I want to run them and pass a string parameter to my main.

Code Sample:

package dfa;
public class Main {

public static void main(String[] args) {

    DFA myDFA = new DFA();

    run(myDFA, args);
}

public static void run(DFA myDFA, String[] args)
{
    String test = args[0];
    if(myDFA.accept(test))
        System.out.println("yes");
    else
        System.out.println("no");
}
}

How I am running it:

java -classpath . Main.class testString

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: Main/class
Caused by: java.lang.ClassNotFoundException:Main.class
.
.
.
.
Could not find the main class: Main.class

New Error:

Exception in thread "main" java.lang.NoClassDefFoundError: dfa/class
Caused by: java.lang.ClassNotFoundException:dfa.class
....Could not find the main class: dfa.Main
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:20:19+00:00Added an answer on May 16, 2026 at 4:20 pm

    You shouldn’t put the .class extension when your run java.

    java -classpath . Main testString is enough if you class is in the default package.


    By default, the first non-option argument is the name of the class to be invoked. A fully-qualified class name should be used.

    It means that if your class is in a package you have to use java my.package.project.Main

    In your case :

    java -classpath . dfa.Main testString
    

    To execute this command you must be in the parent folder of dfa directory.


    Resources :

    • Java documentation for Unix
    • Java documentation for Windows
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey this might be a simple question, but i have been stumped on it
Hey guys, sorry for this probably fairly simple question but I'm starting to get
Hey this is probably a dumb question but i can't seem to find a
Hey, I am guessing that this is probably fairly trivial, but I am having
Hey guys I know that this is probably just a simple sql statement but
Hey guys. This is a very simple question, I'm sure, but I'm getting myself
This is probably an easy question, but hey, i'm a beginner. So I've created
Hey this is a simple question but i can't seem to find an answer
Hey this may be a somewhat simple question, but I'm new to Eclipse and
Hey all i am probably overthinking this but how can i check the textbox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.