長い努力の後、私はこのコードで私の問題を診断します、ブロックでflag
falseになる場合catch
は決してtrueになりません..有効な入力を与えても、
それはどうですか?catchブロックでフラグ値がfalseになったときにその問題を解決する方法は、1回がfalseになった後は常にfalseを表示し、正しい入力を行うと無効な入力メッセージを出力します
public class AgAppHelperMethods {
private static final String LOG_TAG = null;
private static AgAppHelperMethods instance = null;
static boolean flag=true;
public static String varMobileNo;
public static String varPinNo;
String[][] xmlRespone = null;
public static AgAppHelperMethods getInstance()
{
if(instance == null)
{
instance = new AgAppHelperMethods();
}
return instance;
}
public static String[][] AgAppXMLParser( String parUrl) {
String _node,_element;
String[][] xmlRespone = null;
HttpURLConnection urlConnection = null;
try {
String url = ("www.xyz.com....");
URL finalUrl = new URL(url);
urlConnection = (HttpURLConnection) finalUrl.openConnection();
urlConnection.setUseCaches(false);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new
InputSource(urlConnection.getInputStream()));
doc.getDocumentElement().normalize();
NodeList list=doc.getElementsByTagName("*");
_node=new String();
_element = new String();
xmlRespone = new String[list.getLength()][2];
//this "for" loop is used to parse through the
//XML document and extract all elements and their
//value, so they can be displayed on the device
for (int i=0;i<list.getLength();i++)
{
Node value=list.item(i). getChildNodes().item(0);
_node=list.item(i).getNodeName();
_element=value.getNodeValue();
xmlRespone[i][0] = _node;
xmlRespone[i][1] = _element;
}//end for
urlConnection.disconnect();
}//end try
catch (Exception e)
{
String[][] res;
flag=false;
Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e);
public class AgAppTransAirTimeTopUp extends Activity {
btnTATsubmit.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
submitATTP();
}
}
});
protected void submitATTP() {
xmlResponse = AgAppHelperMethods.AgAppXMLParser("Axyz......");
if(!AgAppHelperMethods.flag)
{
Toast.makeText(getApplicationContext(), "Invalid Input " ,
Toast.LENGTH_SHORT).show();
}
else {
Intent j = new Intent(AgAppTransAirTimeTopUp.this, AgAppTransATTPResponse.class);