叫做請看看我的代碼..從錯誤的線程異常
public class BseDemo extends Activity {
final String feedUrlString = "http://www.bseindia.com/sensex/xml-data/sensexrss.xml";
Uri uri;
TextView tvs,tvd;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bse b = new Bse();
b.start();
}
class Bse extends Thread{
public void run(){
try {
tvs = (TextView)findViewById(R.id.text);
tvd = (TextView)findViewById(R.id.diff);
URL url = new URL(feedUrlString);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
Element e = doc.getDocumentElement();
NodeList nl = e.getElementsByTagName("title");
Node bse = nl.item(2);
String sen = bse.getFirstChild().getNodeValue();
tvs.setText(sen.substring(0, sen.indexOf("*")));
tvd.setText(sen.substring(sen.indexOf("*")+1));
tvd.setBackgroundResource(R.drawable.plus);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
我上面提到的代碼和我得到異常CalledFromWrongTreadException
請給一些解決方案。
你在哪個行中發生異常?你能提一下嗎? –