amazingCarrotSoup amazingCarrotSoup - 3 years ago 150
Java Question

class constructor takes file as string yet constructor not happy with string java

I have the following class and its constructor just the parts of the class needed to show for the question are shown:

public class TestFile {
private File file;

// constructor takes test file location as a string

public TestFile(String testFile){
file = new File(testFile);

then when I go to the test file I created to test this class I have the following error.

public class TestFileTest {
public void readfile(){
TestFileTest greaterthree = new TestFileTest("./filesfortests/greaterthree.txt");
assetEquals("more than 3 lines", 1, greaterthree.readfile());


error below:

TestFileTest( ) 
in TestFileTest cannot be applied

Answer Source


TestFileTest greaterthree = new TestFileTest("./filesfortests/greaterthree.txt");

should be

TestFile greaterthree = new TestFile("./filesfortests/greaterthree.txt");

You get that error, because you selected the "Tester" to instantiate it (but it doesn't take a String).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download