Take the 2-minute tour ×

I'm wondering what I'm doing wrong with this: Currently testing the StringDirective class, which is supposed to parse the input string for the name of the String variable to be created. I was thinking I've set the TPLString class up correctly but get a whole boatload of cannot find symbol errors on multiple lines-- are the parameters I passed in wrong? This code is supposed to parse a String, split it in two parts, parse it for a String variable name, and then assign it an empty string as a value for now, and then store the information about the variable's name and value in a HashMap.

public class StringStatement implements Directive
{   /** StringStatement implements the STRING keyword as defined in class TPLString.
    *   This keyword declares a String variable.
    *   A declared String is empty when first instantiated.

    public void execute(String[] parts)
        //instantiate a TPLString
        String temp=parts[1];
        String[] placeholder = temp.split("[\\s+]");
        String name=placeholder[0];
        String value;

        variables.addVariable(name, value);//add variable to variables hashmap

//variable classes

abstract class TPLVariable
    String name;
    TPLVariable(String s)
        name = s;

class TPLInt extends TPLVariable
    int intValue;
    TPLInt(String s, int v)

class TPLString extends TPLVariable
    String stringValue;
    TPLString(String s, String str)


//add to variables HashMap

class TPLVariables  
    private Map<String, TPLVariables> variables = new HashMap<String, TPLVariables>();  

    public void addVariable(String name, String value)  
// Parses the declaration String, create a TPLVariable of the appropriate type   
// and add it to the map using the variable name as the key 


            TPLString stringDeclaration= new TPLString(name, value);
            variables.put(name, TPLString(name, value));
            System.out.println(name+ " hex0");//debug
            System.out.println(value+ " hex1");//debug

            TPLInt integerDeclaration= new TPLInt(name, value);
            variables.put(name, TPLInt(name, value));
            System.out.println(name+ " hex2");//debug
            System.out.println(value+ " hex3");//debug

share|improve this question
What specific errors are you getting? Are you including the needed files? –  cdeszaq Jan 18 '12 at 16:42
Yeah, reckon I have-- the only code not included is the original methods for parsing the String into a format [keyword+ values]; that's for the first HashMap that maps to the Directive classes e.g. the StringDirective class above. –  Luinithil Jan 18 '12 at 17:01
@cdeszaq The first error that's a big concern is the one where it says it can't find the TPLString in the line variables.put(name,TPLString(name, value)); –  Luinithil Jan 18 '12 at 17:07
I see no package or import declarations -- are all your classes in the default package? –  Tom G Jan 18 '12 at 17:25
@Tom G Yes. left off the import declarations since those are fine: the import declarations are import.java.io.*; import java.util.*; –  Luinithil Jan 18 '12 at 17:34

1 Answer 1

up vote 0 down vote accepted

TPLString(name, value) is not a correct syntax.

If you want a new TPLVariable, you should add new keyword before it.

variables.put(name, new TPLString(name, value));

If you want to reference previous variable you declare, you should use it's name

TPLString stringDeclaration= new TPLString(name, value);
variables.put(name, stringDeclaration);

I suggest you can follow SSCCE principle to post question next time

share|improve this answer

Your Answer


