I am trying to run this code in my android application in a non GUI related class.
Thread connection = new Thread(new Runnable() {
public void run() {
try {
streamSource = new StreamSource(conn.getInputStream());
writer = new CharArrayWriter();
StreamResult streamResult = new StreamResult(writer);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(streamSource, streamResult);
} catch (Exception e) {
e.printStackTrace();
}
}
});
connection.start();
The issue is that when I call writer, I am getting a null value. Writer is defined as a static global variable as well as streamSource. I'm not good with threads and this seems like my main thread is not seeing that my writer is created.
Any help?
writerbefore you read it?