java: constructor ranngeIpScanner in class cannot be applied to given types; -
im new in java have class :
public class ranngeipscanner { public static void main(string ipaddress) { string ipaddress = ipaddress; string[] octets = ipaddress.split("\\."); system.out.println(octets); //some more work here ... } }
and instantiated in class :
ranngeipscanner scanip = new ranngeipscanner("192.198.1.200");
when try compile following error
error:(45, 42) java: constructor ranngeipscanner in class com.server.scanner.ranngeipscanner cannot applied given types; required: no arguments found: java.lang.string reason: actual , formal argument lists differ in length
forgive me if question little noob didnt know search for
thanks
in java, main
method different constructor class.
your code above declares main
method, not define constructor. result, java implicitly creates default constructor:
public ranngeipscanner() { super(); }
note default constructor has no parameters.
when write line...
ranngeipscanner scanip = new ranngeipscanner("192.198.1.200");
...you calling constructor, not main
method. thus, java complains attempting give string
ranngeipscanner
's constructor, default takes no arguments.
the fix easy: instead of
public static void main(string ipaddress)
you should write
public ranngeipscanner(string ipaddress)
this changes main
method constructor class.
also, little tip: java convention start class names capital letters , variable names lowercase ones. class ranngeipscanner
better named rangeipscanner
, , variable ipaddress
should called ipaddress
.
Comments
Post a Comment