Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input redirection into Java - Could not find or load main class

Tags:

I tried every online solution and i still get the same result..i'm trying to get my code to run on a file "distinct.txt" and here is my attempt to run it.

here is my try

i tried different paths and all give same result.

here is my code

package pset2.sol; import edu.princeton.cs.algs4.StdIn; public class Permutation { public static void main(String[] args){     RandomizedQueue<String> rq = new RandomizedQueue<>();     while (!StdIn.isEmpty()) {         String item = StdIn.readString();         rq.enqueue(item);     }     int k = Integer.parseInt(args[0]);     for(int i = 0; i < k; i++){         System.out.println(rq.dequeue());     } } } 
like image 951
Ahmad Fahmy Avatar asked Feb 03 '17 14:02

Ahmad Fahmy


People also ask

Could not find or load main class main Java?

Reasons why Java cannot find the class When you get the message "Could not find or load main class ...", that means that the first step has failed. The java command was not able to find the class. And indeed, the "..." in the message will be the fully qualified class name that java is looking for.

Could not load main class Java linux?

The error 'Could not find or load main class' occurs when using a java command in the command prompt to launch a Java program by specifying the class name in the terminal. The reason why this happens is mostly due to the user's programming mistake while declaring the class.


1 Answers

My guess is that your source-folder is not set correctly.

Try File -> Project Structure -> Modules -> (tab) Sources -> Mark as: Sources.

That fixed the problem for me after importing an Eclipse Project.

like image 193
matejetz Avatar answered Sep 28 '22 12:09

matejetz