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

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 博客专家认证 2017-04-24 04:32
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记