我想在这里创建XML文件是我的以下代码
String fileName = "jasstech.xml";
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = null;**
try
{
xtw = xof.createXMLStreamWriter(new FileOutputStream(fileName), "UTF-8");
xtw.writeStartDocument("UTF-8", "1.0");
xtw.writeStartElement("root");
xtw.writeComment("This is an attempt to create an XML file with StAX");
xtw.writeStartElement("foo");
xtw.writeAttribute("order", "1");
xtw.writeStartElement("meuh");
xtw.writeAttribute("active", "true");
xtw.writeCharacters("The cows are flying high this Spring");
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeStartElement("bar");
xtw.writeAttribute("order", "2");
xtw.writeStartElement("tcho");
xtw.writeAttribute("kola", "K");
xtw.writeCharacters("Content of tcho tag");
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeEndDocument();
}
catch (XMLStreamException e)
{
e.printStackTrace();
}
catch (IOException ie)
{
ie.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
以上相同代码在JAVA项目中工作正常但在Android项目中给出以下错误
03-03 07:48:40.778: ERROR/AndroidRuntime(719): …Run Code Online (Sandbox Code Playgroud) 我想获取当前在手机中的SIM号码,即所有者号码.和网络模式无论是GSM还是CDMA.
我在网上搜索并尝试通过getLine1Number()进行此操作; 但什么都没有
请帮忙我该怎么做.
我想调用wait()其他Thread becoz如果我当前的类的一部分代码正在执行不想被其他线程中断..为此我这样做
main.class
testThread as=new testThread();
try{
synchronized(as) {
wait();
}
} catch (Exception e) {
Log.d(tag, "In ==Scheduler== error"+e.toString());
}
Run Code Online (Sandbox Code Playgroud)
testThread.class
public void run() {
while(true) {
System.out.println("Thread");
try {
Thread.sleep(6000);
} catch(Exception r) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
并得到以下错误
error java.lang.IllegalMonitorStateException:对象在wait()之前未被线程锁定
为什么我会收到此错误,我该如何解决?