简体   繁体   中英

Cannot Find method error

Below is my code for the Star constructor, i'm passing the correct values but i keep getting a cannot find symbol error for the star constructor

private Star[] star;
st = db.readLineFromDB();
ST = new StringTokenizer(st , ",");
star[count] = Star.Star(Double.valueOf(ST.nextToken()),Double.valueOf(ST.nextToken()),ST.nextToken(),Integer.valueOf(ST.nextToken()),ST.nextToken());
count++;

public Star(double logdist, double vmag, String sp_class, int ID, String name)
 {
 this.logdist = logdist;
 this.vmag = vmag;
 this.sp_class = sp_class;
 this.ID = ID;
 this.name = name;
 }

Thanks guys for the ans... about to give up...

star[count] = new Star(...);

您使用new关键字而不是Class.Class(...)调用构造函数。

Star.Star(Double.valueOf(ST.nextToken()),Double.valueOf(ST.nextToken()),ST.nextToken(),Integer.valueOf(ST.nextToken()),ST.nextToken());

This is not the way to call constructor.

you should do some thing

Star starObj = new Star(Double.valueOf(ST.nextToken()),Double.valueOf(ST.nextToken()),ST.nextToken(),Integer.valueOf(ST.nextToken()),ST.nextToken());

Have a detail look at this tutorial

Instead of

star[count] = Star.Star(Double.valueOf(ST.nextToken()),Double.valueOf(ST.nextToken()),ST.nextToken(),Integer.valueOf(ST.nextToken()),ST.nextToken());

do

star[count] = new Star(Double.valueOf(ST.nextToken()),Double.valueOf(ST.nextToken()),ST.nextToken(),Integer.valueOf(ST.nextToken()),ST.nextToken());

The Star method isn't a public static class so you can't do Star.Star (if that's possible).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM