qq_35026415
qq_35026415
采纳率0%
2017-04-24 03:14

android,cannot resolve method getSharedPerferences

package com.snow.mobilebi;

import android.content.SharedPreferences;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**

  • Created by MECHREV on 2017/4/19. */

public class WebServiceFetchr {

private SharedPreferences pref;

private static final String TAG = "WebServiceFetchr";

public byte[] getUrlByte(String urlSpec) throws IOException{
    URL url = new URL(urlSpec);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();

    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = connection.getInputStream();

        if(connection.getResponseCode() != HttpURLConnection.HTTP_OK){
            throw  new IOException(connection.getResponseMessage() + ": with" + urlSpec);
        }

        int bytesRead = 0;
        byte[] buffer = new byte[1024];
        while ((bytesRead = in.read(buffer)) > 0 ){
            out.write(buffer, 0, bytesRead);
        }
        out.close();
        return  out.toByteArray();
    }finally {
        connection.disconnect();
    }
}

public String getUrlString(String urlSpec) throws IOException{
    return new String(getUrlByte(urlSpec));
}

public void fetchItems(){
    pref = getSharedPerferences("set",MODE_PRVIATE);
    try{
        String url = pref.getString("URL", "");
        String jsonString = getUrlString(url);
        Log.i(TAG, "Received JSON:" + jsonString);
    }catch (IOException ioe){
        Log.e(TAG, "Failed to fetch items", ioe);
    }
}

}

最后部分的pref = getSharedPerferences("set",MODE_PRVIATE);一直报错。。。求帮忙解决。。。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • VNanyesheshou zpy_公众号_码农修仙儿 4年前

    mContext.getSharedPreferences("set",Context.MODE_PRIVATE)

    点赞 4 评论 复制链接分享

相关推荐