关于HashMap的问题(求救!!!!!!!!!!!!!!!!!!!!!)

08-06-18 xiaoG521

这个程序用本类的main方法调用HashMapIter(double x,double y,double x1,double y1)方法时,在HashMapIter(double x,double y,double x1,double y1)里的hashmap就有值,要是在别的类里直接调用HashMapIter(double x,double y,double x1,double y1)方法时,在HashMapIter(double x,double y,double x1,double y1)里的hashmap就是空,为什么啊,帮帮忙

import com.sun.xml.internal.fastinfoset.sax.Properties;
class XmlSax extends DefaultHandler{
public Map hm =new HashMap();
ArrayList hmlist = new ArrayList();
ArrayList hmlist1 = new ArrayList();
int tempnum;
public void parseURI(String uri)
{
try
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse(uri,this);
}
catch (Exception e)
{
e.printStackTrace();
}
}

public void startElement(String namespaceURI, String localName,
String rawName, Attributes attrs)
{


if (attrs != null)
{
int len = attrs.getLength();
System.out.println(len);
for (int i = 0; i < len; i++)
{ if(attrs.getQName(i).equals("lat")||attrs.getQName(i).equals("lon")){

hm.put(attrs.getQName(i)+tempnum, attrs.getValue(i));
if(attrs.getQName(i).equals("lon")){
tempnum++;
}
}
}
}
}
private String getLocationString(SAXParseException ex)
{
StringBuffer str = new StringBuffer();
String systemId = ex.getSystemId();
if (systemId != null)
{
int index = systemId.lastIndexOf('/');
if (index != -1)
systemId = systemId.substring(index + 1);
str.append(systemId);
}

str.append(':');
str.append(ex.getLineNumber());
str.append(':');
str.append(ex.getColumnNumber());
return str.toString();
}

public static void main(String args[]){
XmlSax st=new XmlSax();
st.parseURI("new.xml");
st.HashMapIter(41.818696,123.437490,41.815497,123.436803);
}

public double HashMapIter(double x,double y,double x1,double y1){
XmlSax st=new XmlSax();
st.parseURI("new.xml");
double twoPointrou=0.00;
long ly=(long)(y*1000000);
long ly1=(long)(y1*1000000);
String xx=String.valueOf(ly);
String yy1=String.valueOf(ly1);
System.out.println(x+"aaaaaaaaa"+xx+x1+yy1);
double xz=0.00,yz=0.00,xz1=0.00,yz1=0.00;
String xzj="123456",xzj1="123456";
int xc=10000,xc1=10000;
int i=0,j=0;
System.out.println(hm.get("lon1"));
}
}


[该贴被xiaoG521于2008-06-18 17:01修改过]

cgpping
2008-06-20 14:20

你看看是不是XML文件找不到呢,应用程序与WEB应用有区别的