0

All classes run well in Editplus, but only if I declare Package, the error comes. Compile is good, but when I run this code, the cmd turns out like this.

package PenP;

public class Pen4 
{

    String vender;
    String color;
    int price;

    public Pen4(){
    }

    public Pen4(String name){
        vender = name;
    }

    public Pen4(String name, String col, int pp){
        vender = name;
        color = col;
        price = pp;
    }

    void write(){
        System.out.println("Pen: write()");
        System.out.println("Pen Vender: "+ vender);
        System.out.println("Pen Color: " + color);
        System.out.println("Pen Price: " + price);
    }



    
    

And I import package in another class 'PenP' Error: Could not find or load main class Pen Caused by: java.lang.NoClassDefFoundError: PenP/Pen (wrong name: Pen)

And I import this class 'Pen4' to PenUser.class and compile the main code.

import PenP.Pen4;

class PenUser
{
    public static void main(String[] args) 
    {
        System.out.println("Hello Pen!");


        Pen4 mypen = new Pen4("SMU", "Green",1000);
    
        mypen.erase();
        mypen.write();
        mypen.write(2000);
        mypen.write(3000, "Dept. IT Engineering");
    }
}

And the compile error messages comes out.

PenUser.java:1: error: package PenP does not exist
import PenP.Pen4;
           ^
PenUser.java:10: error: cannot access Pen4
                Pen4 mypen = new Pen4("SMU", "Green",1000);
                ^
  bad class file: .\Pen4.class
    class file contains wrong class: PenP.Pen4
    Please remove or make sure it appears in the correct subdirectory of the classpath.
2 errors

Not only this codes, but also doing every package file turns out like this error. I don't think my classpath is wrong because every normal class file runs well. What do I have to do? Please help..

Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93
chip sumi
  • 1
  • 1

0 Answers0