0

I just made two classes with one package, but when I run program it says 'Could not find or load main class', but when I remove package p; from main program everything is right.package p; package p;

public class Ex5 {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}

Whats wrong with that package?

package p;

public class Help {
    int x;
    int y;

    public void Help(int a, int b)
    {
        x = a;
        y = b;  
    }   

}

2 Answers2

0

in creating a package you must follow the java naming convention

to create a package you must name it using the company website in reverse order

e.g. if your company is dawidyenko.com you should create a package com.dawidyenko;

after creating a package you can then import it in your main method using

import com.dawidyenko.Help;

note that your package is not like java built in packages so you must include the class name and must not use the * wild card symbol

0xDEADBEEF
  • 590
  • 1
  • 5
  • 16
0

This will work for you. You can get everything from the Help class.

import p.Help;
public class Ex5 {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}
Pang
  • 9,564
  • 146
  • 81
  • 122
Mjachowdhury
  • 85
  • 10