0

I have a java file with no main (Call.java) with a set of methods. I have another java file that I want to call the constructor in Call.java. Here is the structure: link to file structure

I'm using the command-line to run java programs.

My question is: how can I do so without getting an error

Source code: Class:

import java.util.*;

public class Call{
    private int userTypedInt;
    Scanner userInput = new Scanner(System.in);

    Call(){
        while(true){
            mainMenu();
        }
    }

    public void mainMenu(){
        System.out.println("\n\t\t####| Main Menu |#### \n");
        System.out.println("\t\t0. Exit the program");
        System.out.println("\t\t1. Option");

        // check that the user typed a number - specifically an int 
        try{
            System.out.print("\nEnter a choice: ");
            userTypedInt = userInput.nextInt();
            path(userTypedInt);
        }catch(InputMismatchException e){
            System.out.println("\n\t\tInvalid entry");
            userInput.nextLine(); // clears the buffer
        }
    }

    public void path(int pick){
        switch(pick){
            case 0:
                userInput.close();
                System.exit(0);
                break;
            case 1:
                break;
            default:
                System.out.println("\t\tInvalid Entry");
        }
    }
}

Test file:

public class Test{
    public static void main(String[] args){
        System.out.println("Online");
        new Call();

    }
}
Henity
  • 3
  • 4
  • 2
    Possible duplicate of [import class in different directory](https://stackoverflow.com/questions/25253758/import-class-in-different-directory) – Remixt Feb 06 '18 at 17:10
  • You have to post your source code or add more information ,that will help more understanding your problem. – e2rabi Feb 06 '18 at 17:22
  • And add screenshots to your question rather than providing links to other sites. – Jaroslaw Pawlak Feb 06 '18 at 17:26
  • it's a link to a stack overflow response I'don't knwo why it displayed like an externe link ! – e2rabi Feb 06 '18 at 17:32
  • @JaroslawPawlak I used the image button and it said I'm still new to Stack Overflow therefore it will post my image as a link – Henity Feb 06 '18 at 17:36
  • Let me also state that I'm using packages and simply want to create a class that I can import into different Java projects – Henity Feb 06 '18 at 18:54
  • 1. Possibility: URLClassLoader, 2. Posibility: add the other class to the classpath – dan1st Jun 12 '19 at 05:12

0 Answers0