0

ライブラリ用のアプリケーションを作成していて、リモート データベースにアクセスする必要があります。次のコードに問題があります。

llave = accountm.getUserData (mAccounts [i], accountm.KEY_USERDATA);

変数 i をインクリメントするループ内にこの行があります。プログラムがこの行に到達すると、エラーが発生し、アプリケーションが予期せず終了します。Eclipse の logcat では、uid が異なります。

関数全体のコードは次のとおりです。

public ArrayList<Grabar> getItems(Context ctx, URL url)throws IOException {

        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);

        URLConnection conn = url.openConnection();
        InputSource is;


        // Build the baseURL in-case we're given relative links in our RSS feed
        baseURL = url.getProtocol() + "://" + url.getHost();
        if ( url.getPort() > 0 )
            baseURL += ":" + url.getPort();         
            AccountManager accountm = AccountManager.get(ctx);
            //Account[] mAccounts = accountm.getAccountsByType("nz.net.catalyst.KiritakiKoha.account");
            Account[] mAccounts = accountm.getAccounts();
            String llave;
            for (int i=0; i < mAccounts.length; i++) {

                    llave=accountm.getUserData(mAccounts[i], accountm.KEY_USERDATA);

                    System.out.println(mAccounts[i]);

                    if ( llave.length() > 0 ) {
                        conn.setRequestProperty("Cookie", llave);
                        break;
                    }
            }

            is = new InputSource(conn.getInputStream());
            xr.parse(is);
            return Grabars;

    } catch (IOException e) {
            Log.e(TAG, "getItems: IOException: " + e.toString());
            throw new IOException("Connection failed.");
    } catch (SAXException e) {
            Log.e(TAG, "getItems: SAXException: " + e.toString());
    } catch (ParserConfigurationException e) {
            Log.e(TAG, "getItems: ParserConfigurationException: " + e.toString());
    }

    return Grabars;
}
4

0 に答える 0