Importing my packages and my methods inside my code?

时间:2016-11-26 18:28:12

标签: java

I am getting this error that the method is not defined for my lab06 class, eventhough I imported it: 1

You can see here that the class MyMethods is inside the package MyPackage: 2

Can anyone tell me why is this not compiling? MyPackage folder (which contains MyMethods files) and lab06 class files are inside the lab06 folder. I would've provided you guys with more pictures but my 'reputation' isn't high enough for that kind of godly gesture.

The problem solves itself if I type MyMethods.spaceCount instead of spaceCount, but it will be a pain to write that in front of every single method I create. Importing should've solved this issue shouldn't it? At least that's what I've seen before.

1 个答案:

答案 0 :(得分:4)

To import static methods so that they don't need a class prefix, you have to use the static keyword in your import:

import static MyPackage.MyMethods.*;