0
我想知道我在做什么错了:目前正在测试StringDirective
类,它应该解析输入字符串以获得要创建的字符串变量的名称。我在想我已经正确地设置了TPLString
类,但是得到了一大堆无法在多行上找到符号错误 - 我通过的参数是错误的吗?这段代码应该解析一个字符串,将它分成两部分,解析为一个字符串变量名称,然后为它分配一个空字符串作为现在的值,然后将关于变量名称和值的信息存储在一个HashMap
。即使定义了类和参数,Java仍找不到符号错误?
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
}
}
//变量类
abstract class TPLVariable
{
String name;
TPLVariable(String s)
{
name = s;
}
}
class TPLInt extends TPLVariable
{
int intValue;
TPLInt(String s, int v)
{
super(s);
intValue=v;
}
}
class TPLString extends TPLVariable
{
String stringValue;
TPLString(String s, String str)
{
super(s);
stringValue=str;
}
}
//添加变量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
if(value.charAt(0)=='"')
{
TPLString stringDeclaration= new TPLString(name, value);
variables.put(name, TPLString(name, value));
System.out.println(name+ " hex0");//debug
System.out.println(value+ " hex1");//debug
}
else
{
TPLInt integerDeclaration= new TPLInt(name, value);
variables.put(name, TPLInt(name, value));
System.out.println(name+ " hex2");//debug
System.out.println(value+ " hex3");//debug
}
}
你得到什么具体的错误?你是否包含所需的文件? – cdeszaq 2012-01-18 16:42:04
是的,我认为 - 唯一没有包含的代码是将字符串解析为[keyword + values]格式的原始方法;这是第一个映射到指令类的HashMap,例如上面的StringDirective类。 – Luinithil 2012-01-18 17:01:05
@cdeszaq第一个值得关注的错误是它说它无法在行'variables.put(name,TPLString(name,value))中找到TPLString';' – Luinithil 2012-01-18 17:07:35