开发者

class constructor cannot be accessed by outside package

开发者 https://www.devze.com 2023-03-28 00:36 出处:网络
so i can\'t fi开发者_Python百科nd a question already asked that answers my exact problem. I have a package that i wrote in eclipse that i exported as a jar library to use in the processing ide. in pro

so i can't fi开发者_Python百科nd a question already asked that answers my exact problem. I have a package that i wrote in eclipse that i exported as a jar library to use in the processing ide. in processing i have a sketch that has a class that calls a class that is in the package. when i try to compile i get this error:

Pirate(processing.core.PApplet,java.lang.String,processing.core.PVector,float,float,int,int) is not public in fsg.pvzclone.pirateunits.Pirate; cannot be accessed from outside package
[javac]   fsg.pvzclone.pirateunits.Pirate pirate1 = new fsg.pvzclone.pirateunits.Pirate(this, "Pirate", pinPoint, pWidth, pHeight, 1, 1).displayPirate();

does anyone know why i can't access the class? I have both the class and constructor set as public, so i'm not sure why the class can't be accessed. any help would be greatly appreciated.

CONSTRUCTOR CODE:

package fsg.pvzclone.pirateunits;

import processing.core.*;

public class Pirate {
   public String pirateClass;
    int classId;
    PVector pinPoint;
    float width;
    float height;
    int id;
    PApplet parent;

    public Pirate(processing.core.PApplet _parent, String _pirateClass, PVector _pinPoint,
        float _width, float _height, int _classId, int _id) {
        parent = _parent;
        pirateClass = _pirateClass;
        classId = _classId;
        width = _width;
        height = _height;
        pinPoint = _pinPoint;
        id = _id;
    }

    public void displayPirate() {
        parent.fill(13, 183, 20, 255);
        parent.stroke(7, 59, 9, 255);
        parent.rect(this.pinPoint.x-this.width/2, (float)(this.pinPoint.y-this.height*.75), this.width, this.height);
    }

}

CODE CALLING PIRATE CLASS:

fsg.pvzclone.pirateunits.Pirate pirate1 = new fsg.pvzclone.pirateunits.Pirate(this, "Pirate", pinPoint, pWidth, pHeight, 1, 1).displayPirate();


try to create public default constructor in Pirate class and try to call it as:

public class Pirate{
 public Pirate () {}

  ....
}

calling code:

fsg.pvzclone.pirateunits.Pirate emptyPirate1 =  new fsg.pvzclone.pirateunits.Pirate();

And check you still get the same error msg?


Not sure this is your problem, but it is a problem and too long for a comment - you should replace;

fsg.pvzclone.pirateunits.Pirate pirate1 = new fsg.pvzclone.pirateunits.Pirate(this, "Pirate", pinPoint, pWidth, pHeight, 1, 1).displayPirate();

with:

fsg.pvzclone.pirateunits.Pirate pirate1 = new fsg.pvzclone.pirateunits.Pirate(this, "Pirate", pinPoint, pWidth, pHeight, 1, 1);
pirate1.displayPirate();

Since displayPirate returns nothing, not a pirate.


If the Pirate class is 1:1 like shown, then I suspect you have an old version in classpath somewhere. Double-check the classpath for old versions, both .java and .class.

0

精彩评论

暂无评论...
验证码 换一张
取 消