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 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型