-1

我刚刚为我构建的 Android 应用程序创建了我的第一个库(我有我需要在未来跨不同应用程序重用的代码)并且我需要从库中启动我在主项目中拥有的方法 - 但是当我尝试使用以下行来做到这一点:

com.project.sample.datasettings.UpdateActivity.success();

我收到一个编译器错误,说明:

com.project.sample.UpdateActivity Cannot Be Resolved To A Type

资源:

package com.project.sample.networktasklibrary;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLException;
import com.project.sample.networktasklibrary.XmlParserHandlerFinal;
import com.project.sample*;

import org.xml.sax.SAXException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

// 这个类在后台执行对 webservice 的调用

public class NetworkTask extends AsyncTask<String, String, InputStream> {
    private static final String LOG_TAG = "STDataSettings";
    private static final String TAG_RESULT = "success";
    private static InputStream stream;

    @Override
    protected InputStream doInBackground(String... params) {

        try {
            stream = getQueryResults("https://dl.dropboxusercontent.com/u/31771876/GetPhoneSettings-ST-rsp-eng.xml");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return stream;
    }

    /*
     * Sends a query to server and gets back the parsed results in a bundle
     * urlQueryString - URL for calling the webservice
     */
    protected static synchronized InputStream getQueryResults(
            String urlQueryString) throws IOException, SAXException,
            SSLException, SocketTimeoutException, Exception {
        Bundle queryResults = new Bundle();

        HttpsURLConnection https = null;
        String uri = urlQueryString;
        URL urlo = new URL(uri);

        https = (HttpsURLConnection) urlo.openConnection();
        https.setConnectTimeout(50000); // 20 second timeout
        https.setRequestProperty("Connection", "Keep-Alive");
        try {
            https = (HttpsURLConnection) urlo.openConnection();

            if ("gzip".equals(https.getContentEncoding())) {
                stream = new GZIPInputStream(stream);
            } else
                stream = https.getInputStream();

        } catch (SSLException e) {
            Log.e(LOG_TAG, e.toString());
            e.printStackTrace();

        } catch (SocketTimeoutException e) {
            Log.e(LOG_TAG, e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(LOG_TAG, e.toString());
            e.printStackTrace();

        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
            e.printStackTrace();

        } finally {

        }

        String queryResult = null;
        queryResults.putString(TAG_RESULT, queryResult);

        return stream;
    }

    public InputStream getInputStream() {
        return stream;
    }

    protected void onPostExecute(InputStream queryResults) {
        // TODO Auto-generated method stub
        super.onPostExecute(queryResults);
        com.project.sample.datasettings.UpdateActivity.success();
    }
}

更新活动代码示例:

public void success() {

        // to parse the response
        try {
            handler.getQueryResponse(stream);

        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // to set method to save the ArryaLists from the parser
        setArrayList();
        Intent i = new Intent(this, ConfigFinalActivity.class);
        startActivity(i);

    }
4

1 回答 1

0

您是否曾尝试将库添加到主项目中?右键单击项目名称 -> 属性 -> Android -> 添加。然后选择库项目。

于 2013-08-27T14:59:19.170 回答