Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Google Glass SimpleWeatherApp getCity函数返回null_Java_Android_Json_Google Glass_Google Gdk - Fatal编程技术网

Java Google Glass SimpleWeatherApp getCity函数返回null

Java Google Glass SimpleWeatherApp getCity函数返回null,java,android,json,google-glass,google-gdk,Java,Android,Json,Google Glass,Google Gdk,我正在尝试将simple weather app()重新适配到Google Glass,它在Android上返回一个json对象并工作,但是在我的Google Glass中,当我想使用getCity函数时,我有一个空指针异常错误 我的getCity函数与SimpleWeatherApp中的函数相同 public String getCity(){ return prefs.getString("city", "Jerusalem, IL"); } 有3个Java文件,2个类和

我正在尝试将simple weather app()重新适配到Google Glass,它在Android上返回一个json对象并工作,但是在我的Google Glass中,当我想使用getCity函数时,我有一个空指针异常错误

我的getCity函数与SimpleWeatherApp中的函数相同

    public String getCity(){

    return prefs.getString("city", "Jerusalem, IL");
}
有3个Java文件,2个类和1个活动

Citypreference,返回城市并获取城市

RemoteFetch以获取Json对象

为google glass构建视图并显示所需信息的主要活动

我可以分享给你整个项目,如果你想要更多的信息

这是我主要活动内容的一部分 私有视图buildView(){ cardbuildercard=新的CardBuilder(这是CardBuilder.Layout.TEXT); card.setText(R.string.open\u weather\u maps\u app\u id); //更新AtherData(新的CityPreference(getActivity()).getCity())


这意味着我的json对象为空。对于remotefetch.java,您可以在我的文章顶部的SimpleWeatherApp链接中找到它

public String getCity(){

    if(prefs != null)
        return prefs.getString("city", "Jerusalem, IL");

    return "city_not_initialized";
}

或者共享更多代码

您是否初始化了
prefs
?可能是现在的重复,我有一个新错误,但这是我写的错误,因此很好:(抱歉,没有找到天气数据)我将编辑我的主要帖子以分享更多信息info@user3272072正如我在您发布的链接中看到的,CityPreference构造函数需要一个活动。您是否制作了不同的CityPref?如果是,请将该代码粘贴为welll@user3272072抱歉..我看到你写了两次,所以感到困惑…阅读…@user3272072你现在从哪里得到错误?如果你得到的是
city\u未初始化
然后
Prefs
未初始化。请在问题中粘贴错误谢谢你的回答,我没有找到天气数据,因此Json对象看起来是空的。
public String getCity(){

    if(prefs != null)
        return prefs.getString("city", "Jerusalem, IL");

    return "city_not_initialized";
}