値を取得している間、値を取得できません。以下のコードで IOexcetion が発生するのはなぜですか? ハンドラーに何か問題がありますが、私はそれを理解することができません。
public SitesList opCodeRequest(String code)
{
SitesList objsitelist =null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet method= new HttpGet();
method.setURI(new URI(AppConstatnt.OPCODE_URL+code));
HttpResponse response=client.execute(method);
HttpEntity entity=response.getEntity();
InputStream stream=entity.getContent();
Log.e("b4 execute in login","aditya");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
OPCodeHandler myopcodeHandler = new OPCodeHandler();
xr.setContentHandler(myopcodeHandler);
xr.parse(new InputSource(stream));
objsitelist = myopcodeHandler.getSiteList();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();//error
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
return objsitelist;
}
ハンドラ
public class OPCodeHandler extends DefaultHandler {
boolean currentElement = false;
String currentValue = "";
SitesList siteobject;
public SitesList getSiteList() {
return siteobject;
}
public void setSiteList(SitesList objsite) {
siteobject = objsite;
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
currentValue = "";
if (localName.equalsIgnoreCase("opcode")) {
siteobject = new SitesList();
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
if (localName.equalsIgnoreCase("tsip")) {
siteobject.setTsip(currentValue);
}
if (localName.equalsIgnoreCase("ssip")) {
siteobject.setSsip(currentValue);
}
if (localName.equalsIgnoreCase("brand")) {
siteobject.setBrand(currentValue);
}
if (localName.equalsIgnoreCase("balance")) {
siteobject.setBalance(currentValue);
}
if (localName.equalsIgnoreCase("rates")) {
siteobject.setRates(currentValue);
}
if (localName.equalsIgnoreCase("domain")) {
siteobject.setDomain(currentValue);
}
if (localName.equalsIgnoreCase("operator")) {
siteobject.setOperator(currentValue);
}
if (localName.equalsIgnoreCase("active")) {
siteobject.setActive(currentValue);
}
if (localName.equalsIgnoreCase("opcode")) {
setSiteList(siteobject);
}
}
}
値を取得しているアクティビティ。
@Override
protected void onPostExecute(SitesList result)
{
if(this.objprogress.isShowing())
{
this.objprogress.dismiss();
}
tsip = result.getTsip();
ssip = result.getSsip();
brand = result.getBrand();
balance = result.getBalance();
rates = result.getRates();
domain = result.getDomain();
operator = result.getOperator();
active = result.getActive();
}
ログキャット:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.sample.test.SampleAppActivity$Communicator.onPostExecute(SampleAppActivity.java:161)
at com.sample.test.SampleAppActivity$Communicator.onPostExecute(SampleAppActivity.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)