0

我正在尝试从 ArrayList 中提取数据,但是我无法这样做。每次我尝试它都不会返回我正在寻找的值。当我尝试观看它时,我得到:

"nameArr"    (id=830007853896)  
"ApnArr"     (id=830007853920)  
"mmscArr"    (id=830007888688)

当我在 Eclipse 的调试器中查看表达式窗口时 - 当我尝试从表达式窗口中复制和粘贴相同的值时(您可以在其中“观察”不同的值),我得到:

"nameArr"    (pending)  
"ApnArr"     (pending)  
"mmscArr"    (pending)  

...这不是它们应该包含的值。简而言之:问题是当我尝试运行应用程序时,由于我得到的空值而不断卡在我的 tryagain() 方法中,并且我无法弄清楚如何让它们正确填充。

附言

非常感谢任何调试提示/指针。

ConfigFinalActivity 源代码片段(完整代码显示在本页底部):

/** Called when the activity is first created. */
    @SuppressLint("NewApi")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int version = android.os.Build.VERSION.SDK_INT;
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        update = new UpdateActivity();

        //handler.setContext(this.getBaseContext());
        getArrayLists();
        /*
         * boolean deleted = deleteFile("settings.xml");if(deleted){
         * Log.v("settings.xml","deleted"); }else
         * Log.v("settings.xml","failed to delete the file");
         */
        if (ApnArr.isEmpty() || mmscArr.isEmpty()) {

            tryagain();
        } else 
            if (version < VERSION_CODES.ICE_CREAM_SANDWICH) {

            // Update APN table
            try {
                result = updateTable();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }// Settings updated with this atomic call
            catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (result != -1) {
                status = "success";

            } else {
                status = "failure";
            }

            if (status.equals("success")) {
                completeUpdate();
            } else if (status.equals("failure")) {
                tryagain();

            }

        } else {// ICS and later versions

            // Reduce number of steps to 6
            TotalSteps = 6;
            setContentView(R.layout.assist_instructions);
            String assistUpdate = getString(R.string.instructions_1);
            CharSequence styledText = Html.fromHtml(assistUpdate);
            TextView assistText = (TextView) findViewById(R.id.apn_app_text_cta2);
            assistText.setText(styledText);
            mAssistUpdateButton = (Button) findViewById(R.id.assist_update_btn);
            mAssistUpdateButton.setOnClickListener(this);

        }
    }

    private void getArrayLists() {
        nameArr = update.getnameArr();
        ApnArr = update.getApnArr();
        mmscArr = update.getMMSCArr();
        portArr = update.getPortArr();
        count = update.getCount();  
        queryResult = update.getResult();
    }

XMLParserHandlerFinal:

public class XmlParserHandlerFinal extends DefaultHandler {

    public static String queryResult;
    private String tagName="", Value="",result = "";

    public ArrayList<String> NameArr = new ArrayList<String>();
    public ArrayList<String> ValueArr = new ArrayList<String>();
    public ArrayList<String> nameArr = new ArrayList<String>();
    public ArrayList<String> ApnArr = new ArrayList<String>();
    public ArrayList<String> mmscArr = new ArrayList<String>();
    public ArrayList<String> mmsportArr = new ArrayList<String>();
    public ArrayList<String> mmsproxyArr = new ArrayList<String>();
    public ArrayList<String> portArr = new ArrayList<String>();
    public ArrayList<String> proxyArr = new ArrayList<String>();
    public ArrayList<ContentValues> ArrValues = new ArrayList<ContentValues>();
    public ContentValues values = new ContentValues();
    public int count = 0;
    Context c;

    private boolean isPhoneSettings = false, isSettings = false,
            isName = false, isValue = false,isResult = false;

    public XmlParserHandlerFinal() {

    }

    public void setContext(Context c) {
        this.c = c;
    }


    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes atts) {
        if(qName.equals("message")){
            isResult= true;
        }

        if (qName.equals("PhoneSettings")) {

            isPhoneSettings = true;

        }
        if (qName.equals("setting")) {

            isSettings = true;

        }
        if (localName.equals("name")) {

            isName = true;

        }
        if (qName.equals("value")) {
            isValue = true;

        }
    }

    public void endElement(String uri, String localName, String qName)
            throws SAXException {

        if(isResult){
            isResult = false;
        }
        if (isPhoneSettings) {

            isPhoneSettings = false;

        }
        if (isSettings) {

            isSettings = false;

        }
        if (isName) {
            isName = false;
        }
        if (isValue) {

            isValue = false;
        }
    }

    public void characters(char ch[], int start, int length)
            throws SAXException {
        if(isResult){
            result = new String(ch, start, length);
            Log.v("result",result);

        }

        if (isName) {

            tagName = new String(ch, start, length);

            NameArr.add(tagName);

        }
        if (isValue) {


            Value = new String(ch, start, length);

            ValueArr.add(Value);
            values.put(tagName, Value);
            if (tagName.equals("NAME")) {

                Log.v("name",Value);
                nameArr.add(Value);


            } else if (tagName.equals("APN")) {
                Log.v("Apn", Value);
                ApnArr.add(Value);

            } else if (tagName.equals("MMSC")) {
                count++;

                mmscArr.add(Value);
                ArrValues.add(values);
                Log.v("value", Value);
                System.out.println("size " + ArrValues.size());
                System.out.println("values " + values);
            }  else if (tagName.equals("PORT")) {
                Log.v("port", Value);
                portArr.add(Value);
            } else

            if (tagName.equals("APN Settings")) {


            }

        }

    }

    public String getQueryResponse(FileInputStream in) throws SAXException,
            IOException {

        try {


            InputStream istream = in ;

            SAXParserFactory spf = SAXParserFactory.newInstance();
            Log.v("In the parser", "now");
            SAXParser sp;
            sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);


            xr.parse(new InputSource(istream));
        } catch (ParserConfigurationException e) {

            Log.e("", "XML Handler Exception: " + e.toString());
        }

        return result;
    }

    public String getResult(){
        return result;
    }
    public int getCount() {
        return count;
    }

    public ArrayList<String> getNameArr() {
        for (int i = 0; i <= NameArr.size() - 1; i++) {
            System.out.println(NameArr.get(i));
        }
        return NameArr;
    }

    public ArrayList<String> getValueArr() {
        for (int i = 0; i <= ValueArr.size() - 1; i++) {
            System.out.println(ValueArr.get(i));
        }
        return ValueArr;
    }

    public ArrayList<String> getnameArr() {
        for (int i = 0; i <= nameArr.size() - 1; i++) {
            System.out.println(nameArr.get(i));
        }
        return nameArr;
    }

    public ArrayList<String> getApnArr() {
        for (int i = 0; i <= ApnArr.size() - 1; i++) {
            System.out.println(ApnArr.get(i));
        }
        return ApnArr;
    }

    public ArrayList<String> getMMSCArr() {

        return mmscArr;
    }

    public ArrayList<String> getMmscProxyArr() {

        return mmsproxyArr;
    }

    public ArrayList<String> getMmsPortArr() {

        return mmsportArr;
    }

    public ArrayList<String> getProxyArr() {

        return proxyArr;
    }

    public ArrayList<String> getPortArr() {

        return portArr;
    }

    public ArrayList<ContentValues> getArrValuesArr() {
        return ArrValues;
    }

    public void parser(UpdateActivity mainActivity) {
        // TODO Auto-generated method stub

    }

}

日志猫:

09-05 19:45:16.725: W/ActivityThread(5607): Application com.project.new.datasettings is waiting for the debugger on port 8100...
09-05 19:45:16.735: I/System.out(5607): Sending WAIT chunk
09-05 19:45:16.755: I/dalvikvm(5607): Debugger is active
09-05 19:45:16.935: I/System.out(5607): Debugger has connected
09-05 19:45:16.935: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:17.135: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:17.335: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:17.540: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:17.740: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:17.940: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:18.140: I/System.out(5607): waiting for debugger to settle...
09-05 19:45:18.355: I/System.out(5607): debugger has settled (1492)
09-05 19:45:18.535: D/dalvikvm(5607): GC_EXTERNAL_ALLOC freed 57K, 43% free 3084K/5379K, external 0K/0K, paused 50ms
09-05 19:45:18.595: D/dalvikvm(5607): GC_EXTERNAL_ALLOC freed 1K, 43% free 3085K/5379K, external 1K/513K, paused 50ms
09-05 19:45:18.670: D/dalvikvm(5607): GC_EXTERNAL_ALLOC freed 5K, 43% free 3091K/5379K, external 2167K/2538K, paused 28ms
09-05 19:45:18.685: I/System.out(5607): Sim State5
09-05 19:45:18.700: D/Network Availability(5607): CONNECTED
09-05 19:45:18.700: D/Network Availability(5607): NetworkInfo: type: mobile[UMTS], state: CONNECTED/CONNECTED, reason: gprsAttached, extra: wap.new, roaming: false, failover: false, isAvailable: true
09-05 19:45:18.805: D/CLIPBOARD(5607): Hide Clipboard dialog at Starting input: finished by someone else... !
09-05 19:45:19.990: D/ICCID(5607): 8901260832120867967
09-05 19:45:20.000: I/System.out(5607): ICCID%1234 = 587
09-05 19:45:20.000: I/System.out(5607): ICCID/1234 = 7213339410146570
09-05 19:45:20.045: D/dalvikvm(5607): GC_EXTERNAL_ALLOC freed 20K, 42% free 3130K/5379K, external 2664K/3205K, paused 40ms
09-05 19:45:20.090: I/url...(5607): https://wapgate.example.com/REST/phoneSettings
09-05 19:45:20.195: V/httpPost(5607): org.apache.http.client.methods.HttpPost@40538510
09-05 19:45:38.385: D/dalvikvm(5607): GC_FOR_MALLOC freed 132K, 42% free 3285K/5575K, external 4561K/5679K, paused 62ms
09-05 19:45:40.670: I/System.out(5607): response....org.apache.http.message.BasicHttpResponse@405246e8
09-05 19:45:40.670: V/response...(5607): org.apache.http.message.BasicHttpResponse@405246e8
09-05 19:45:40.705: V/In the parser(5607): now
09-05 19:45:40.720: W/System.err(5607): org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
09-05 19:45:40.725: W/System.err(5607):     at org.apache.harmony.xml.ExpatParser.finish(ExpatParser.java:550)
09-05 19:45:40.725: W/System.err(5607):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:480)
09-05 19:45:40.730: W/System.err(5607):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
09-05 19:45:40.735: W/System.err(5607):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
09-05 19:45:40.735: W/System.err(5607):     at com.project.new.datasettings.XmlParserHandlerFinal.getQueryResponse(XmlParserHandlerFinal.java:176)
09-05 19:45:40.740: W/System.err(5607):     at com.project.new.datasettings.UpdateActivity.success(UpdateActivity.java:535)
09-05 19:45:40.745: W/System.err(5607):     at com.project.new.datasettings.UpdateActivity$NetworkTask.onPostExecute(UpdateActivity.java:490)
09-05 19:45:40.745: W/System.err(5607):     at com.project.new.datasettings.UpdateActivity$NetworkTask.onPostExecute(UpdateActivity.java:1)
09-05 19:45:40.750: W/System.err(5607):     at android.os.AsyncTask.finish(AsyncTask.java:417)
09-05 19:45:40.755: W/System.err(5607):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
09-05 19:45:40.755: W/System.err(5607):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
09-05 19:45:40.760: W/System.err(5607):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 19:45:40.765: W/System.err(5607):     at android.os.Looper.loop(Looper.java:130)
09-05 19:45:40.765: W/System.err(5607):     at android.app.ActivityThread.main(ActivityThread.java:3691)
09-05 19:45:40.765: W/System.err(5607):     at java.lang.reflect.Method.invokeNative(Native Method)
09-05 19:45:40.765: W/System.err(5607):     at java.lang.reflect.Method.invoke(Method.java:507)
09-05 19:45:40.765: W/System.err(5607):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
09-05 19:45:40.770: W/System.err(5607):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
09-05 19:45:40.770: W/System.err(5607):     at dalvik.system.NativeStart.main(Native Method)
09-05 19:45:40.850: I/dalvikvm(5607): Failed resolving Lcom/new/project/datasettings/NotificationActivityForMultiProf; interface 26 'Landroid/content/ClipboardManager$OnPrimaryClipChangedListener;'
09-05 19:45:40.850: W/dalvikvm(5607): Link of class 'Lcom/new/project/datasettings/NotificationActivityForMultiProf;' failed
09-05 19:45:40.850: E/dalvikvm(5607): Could not find class 'com.project.new.datasettings.NotificationActivityForMultiProf', referenced from method com.project.new.datasettings.ConfigFinalActivity.showNotification
09-05 19:45:40.850: W/dalvikvm(5607): VFY: unable to resolve const-class 561 (Lcom/new/project/datasettings/NotificationActivityForMultiProf;) in Lcom/new/project/datasettings/ConfigFinalActivity;
09-05 19:45:40.850: D/dalvikvm(5607): VFY: replacing opcode 0x1c at 0x004b
09-05 19:45:40.850: D/dalvikvm(5607): VFY: dead code 0x004d-007f in Lcom/new/project/datasettings/ConfigFinalActivity;.showNotification ()V
09-05 19:45:50.815: I/dalvikvm(5607): threadid=4: reacting to signal 3
09-05 19:45:50.830: D/dalvikvm(5607): threadid=1: still suspended after undo (sc=1 dc=1)
09-05 19:45:50.830: I/dalvikvm(5607): Wrote stack traces to '/data/anr/traces.txt'
09-05 19:45:52.105: I/dalvikvm(5607): threadid=4: reacting to signal 3
09-05 19:45:52.110: D/dalvikvm(5607): threadid=1: still suspended after undo (sc=1 dc=1)
09-05 19:45:52.115: I/dalvikvm(5607): Wrote stack traces to '/data/anr/traces.txt'

完整来源(可能需要完全理解问题):

https://docs.google.com/document/d/1lKnXL1R9f7S7EyYama9OgwoRiRcGRrpO8b-ZUqIPKL0/edit?usp=sharing

4

0 回答 0