I have two files: MyStringLog.java (which extends ArrayStringLog) and TestDriver.java in the same directory. Why doesn't TestDriver.java recognize the MyStringLog constructor from the MyStringLog class? In TestDriver.java I declare:
MyStringLog animals = new MyStringLog("animals");
This is supposed to construct a new MyStringLog object named animals, but I get 2 errors when I compile, both, that MyStringLog symbol is not found.
- ArrayStringLog.java: http://pastebin.com/Z624DRcm
- MyStringLog.java:http://pastebin.com/zaH2S3yg
TestDriver.java:
public class TestDriver { public static void main(String[] args) { MyStringLog animals = new MyStringLog("animals"); animals.insert("dog"); } }
I got this to roughly work. To do so...
for the file
ArrayStringLog.java
, I removed theimplements StringLogInterface
because I simply don't have access to that interface. After doing so, I removed thepackage ch02.stringLogs;
. When I compiled this file with thepackage...
still there, I recieved the error:Exception in thread "main" java.lang.NoClassDefFoundError: ArrayStringLog (wrong name: ch02/stringLogs/ArrayStringLog)
Then in
MyStringLog.java
, I removed theimport ch02.stringLogs.*;
. I then saved and compiled the code, and ran the TestDriver, to which I received no compilation errors.This leads me to believe that your error stems from the
package
statement inArrayStringLog.java
.To finally get a compilation, I put all four files (ArrayStringLog, MyStringLog, StringLogInterface, TestDriver) into the same directory, removed any
package...
statements, added backimplements StringLogInterface
to ArrayStringLog.java, compiled each one, and then ran TestDriver with an addedtoString
method from which the output was:Here was the test driver:
To make clear, ArrayStringLog begins with:
try adding
import MyStringLog;
to your file.Also are you using packages? In which case it should be
import <package_name>.MyStringLog;