Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布尔标志值始终显示为负_Android - Fatal编程技术网

Android 布尔标志值始终显示为负

Android 布尔标志值始终显示为负,android,Android,经过长时间的努力,我诊断出我在这段代码中的问题是,如果flag在catch中变为false,则块永远不会变为true。。即使我提供了有效的输入 告诉我怎么样?当catch块中的标志值变为false时,如何解决该问题:在1次为false后始终显示false,如果我给出正确的输入,则打印无效的输入消息 public class AgAppHelperMethods { private static final String LOG_TAG = null; pr

经过长时间的努力,我诊断出我在这段代码中的问题是,如果
flag
catch
中变为false,则块永远不会变为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);
公共类AgAppHelperMethods{
私有静态最终字符串LOG_TAG=null;
私有静态AgAppHelperMethods实例=null;
静态布尔标志=true;
公共静态字符串varMobileNo;
公共静态字符串varPinNo;
字符串[][]xmlRespone=null;
公共静态AgAppHelperMethods getInstance()
{
if(实例==null)
{
instance=new AgAppHelperMethods();
}
返回实例;
}
公共静态字符串[][]AgAppXMLParser(字符串parUrl){
字符串_节点,_元素;
字符串[][]xmlRespone=null;
HttpURLConnection-urlConnection=null;
试一试{
字符串url=(“www.xyz.com…”);
URL finalUrl=新URL(URL);
urlConnection=(HttpURLConnection)finalUrl.openConnection();
urlConnection.setUseCaches(false);
urlConnection.connect();
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(新建
InputSource(urlConnection.getInputStream());
doc.getDocumentElement().normalize();
节点列表=doc.getElementsByTagName(“*”);
_node=新字符串();
_元素=新字符串();
xmlRespone=新字符串[list.getLength()][2];
//这个“for”循环用于通过
//XML文档并提取所有元素及其
//值,以便它们可以显示在设备上

对于(int i=0;i每次在
AgAppXMLParser
中输入时都用true初始化它,因为变量是静态的

public static   String[][] AgAppXMLParser( String parUrl) { 
   String _node,_element;
   String[][] xmlRespone = null;
   HttpURLConnection urlConnection = null;

   flag = true;

   .....

请(a)格式化您的代码,并(b)准备重现问题的a。我已在活动开始时初始化。请参见上面的我的代码。这是错误,您的变量是静态的。您需要在方法内部初始化它。不要忘记接受答案:)并选中“谁来回答acpet?”?“这篇文章对你有用吗?是的,不,那么点击yes byutton??告诉我如何回答?点击yes,这个姿势对你有用吗?”?