Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.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文件中的字符串资源时出错_Java_Android_String - Fatal编程技术网

读取java文件中的字符串资源时出错

读取java文件中的字符串资源时出错,java,android,string,Java,Android,String,错误:(90,20)错误:不兼容的类型:int无法转换为字符串 如何修复错误 在lineR.string.Invalid_city_name中 使用该方法 getstring(R.string.无效的城市名称) 同样的错误怎么了 status="success"; }else{ status=R.string.Invalid_city_name; } 完整代码: package com.nbdev.app.weat

错误:(90,20)错误:不兼容的类型:int无法转换为字符串 如何修复错误

在lineR.string.Invalid_city_name中

使用该方法

getstring(R.string.无效的城市名称) 同样的错误怎么了

            status="success";
        }else{
            status=R.string.Invalid_city_name;
        }
完整代码:

package com.nbdev.app.weatherapp.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONObject;

import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nbdev.app.weatherapp.ActivityMain;
import com.nbdev.app.weatherapp.adapter.ItemLocationAdapter;
import com.nbdev.app.weatherapp.data.Constant;
import com.nbdev.app.weatherapp.data.DatabaseManager;
import com.nbdev.app.weatherapp.data.GlobalVariable;
import com.nbdev.app.weatherapp.model.City;
import com.nbdev.app.weatherapp.R;
import com.nbdev.app.weatherapp.model.ForecastResponse;
import com.nbdev.app.weatherapp.model.ItemLocation;
import com.nbdev.app.weatherapp.model.WeatherResponse;

public class JSONLoader extends AsyncTask<String, String, ItemLocation>{
    private JSONParser jsonParser = new JSONParser();
    private String jsonWeather = null, 
            jsonForecast= null, 
            status="null";

    private Context ctx;
    private LinearLayout lyt_form;
    private LinearLayout lyt_progress;
    private TextView tv_message; 
    private Dialog dialog;
    private DatabaseManager db;
    private GlobalVariable global;
    private ActivityMain act;

    public JSONLoader(ActivityMain act, LinearLayout lyt_form, LinearLayout lyt_progress, TextView tv_message, Dialog dialog) {
        this.act=act;
        this.ctx=act.getApplicationContext();
        this.lyt_form=lyt_form;
        this.lyt_progress=lyt_progress;
        this.tv_message=tv_message;
        this.dialog=dialog;
        global  = (GlobalVariable) act.getApplication();
        db = new DatabaseManager(act);
    }


    @Override
    protected void onPreExecute() {
        lyt_form.setVisibility(View.GONE);
        lyt_progress.setVisibility(View.VISIBLE);
        super.onPreExecute();
    }

    @Override
    protected ItemLocation doInBackground(String... params) {
        ItemLocation itemLocation   = new ItemLocation();

        try {
            Thread.sleep(50);
            List<NameValuePair> param = new ArrayList<NameValuePair>();
            City city = db.getWordsFormAutocomplate(params[0]);
            if(city!=null){
                itemLocation.setId(city.getId());
                itemLocation.setName(city.getName());
                itemLocation.setCode(city.getCode());

                String url_weather      = Constant.getURLweather(city.getId());
                String url_forecast     = Constant.getURLforecast(city.getId());

                JSONObject json_weather     = jsonParser.makeHttpRequest(url_weather,"POST", param);
                JSONObject json_forecast    = jsonParser.makeHttpRequest(url_forecast,"POST", param);

                jsonWeather     = json_weather.toString();
                jsonForecast    = json_forecast.toString();

                itemLocation.setJsonWeather(jsonWeather);
                itemLocation.setJsonForecast(jsonForecast);

                status="success";
            }else{
                status=(R.string.Invalid_city_name();
            }

        } catch (Exception e) {
            status = e.getMessage();
            e.printStackTrace();
        }

        return itemLocation;
    }

    protected void onPostExecute(ItemLocation result) {
        lyt_form.setVisibility(View.VISIBLE);
        lyt_progress.setVisibility(View.GONE);
        if(status.equals("success")){
            global.saveLocation(result);
            act.refreshList();
            dialog.dismiss();
        }
        tv_message.setText(status);
        //Toast.makeText(ctx, status, Toast.LENGTH_LONG).show();
    };

}
package com.nbdev.app.weatherapp.json;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.json.JSONObject;
导入android.app.Dialog;
导入android.content.Context;
导入android.os.AsyncTask;
导入android.view.view;
导入android.widget.ArrayAdapter;
导入android.widget.LinearLayout;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.nbdev.app.weatherapp.ActivityMain;
导入com.nbdev.app.weatherapp.adapter.ItemLocationAdapter;
导入com.nbdev.app.weatherapp.data.Constant;
导入com.nbdev.app.weatherapp.data.DatabaseManager;
导入com.nbdev.app.weatherapp.data.GlobalVariable;
导入com.nbdev.app.weatherapp.model.City;
导入com.nbdev.app.weatherapp.R;
导入com.nbdev.app.weatherapp.model.ForecastResponse;
导入com.nbdev.app.weatherapp.model.ItemLocation;
导入com.nbdev.app.weatherapp.model.WeatherResponse;
公共类JSONLoader扩展异步任务{
私有JSONParser JSONParser=新JSONParser();
私有字符串jsonWeather=null,
jsonForecast=null,
status=“null”;
私有上下文ctx;
私人线路布局lyt_表;
私人线路布局lyt_进度;
私人文本查看电视信息;
私人对话;
专用数据库管理器数据库;
私人全球可变全球;
私人活动主要法案;
公共JSONLoader(活动主法案、LinearLayout lyt_表单、LinearLayout lyt_进度、文本视图tv_消息、对话框){
这个动作=动作;
this.ctx=act.getApplicationContext();
this.lyt_form=lyt_form;
this.lyt\u progress=lyt\u progress;
this.tv_message=tv_message;
this.dialog=dialog;
global=(GlobalVariable)act.getApplication();
db=新数据库管理器(act);
}
@凌驾
受保护的void onPreExecute(){
lyt_form.setVisibility(View.GONE);
lyt_progress.setVisibility(View.VISIBLE);
super.onPreExecute();
}
@凌驾
受保护的ItemLocation doInBackground(字符串…参数){
ItemLocation ItemLocation=新的ItemLocation();
试一试{
睡眠(50);
List param=new ArrayList();
City-City=db.getWordsFormAutoComplete(参数[0]);
如果(城市!=null){
setId(city.getId());
itemLocation.setName(city.getName());
itemLocation.setCode(city.getCode());
字符串url_weather=Constant.getURLweather(city.getId());
字符串url_forecast=Constant.geturlfecast(city.getId());
JSONObject json_weather=jsonParser.makeHttpRequest(url_weather,“POST”,param);
JSONObject json_forecast=jsonParser.makeHttpRequest(url_forecast,“POST”,param);
jsonWeather=json_weather.toString();
jsonForecast=json_forecast.toString();
itemLocation.setJsonWeather(jsonWeather);
setJsonForecast(jsonForecast);
status=“success”;
}否则{
状态=(R.string.Invalid_city_name();
}
}捕获(例外e){
status=e.getMessage();
e、 printStackTrace();
}
返回项目位置;
}
受保护的void onPostExecute(ItemLocation结果){
lyt_form.setVisibility(View.VISIBLE);
lyt_progress.setVisibility(View.GONE);
如果(状态等于(“成功”)){
全局保存位置(结果);
act.refreshList();
dialog.dismise();
}
tv_message.setText(状态);
//Toast.makeText(ctx,status,Toast.LENGTH_LONG).show();
};
}

您需要一个上下文/活动来从资源中获取字符串

更改此项:

status=R.string.城市名称无效;

对此


status=act.getString(R.string.Invalid_city_name)

将此“status=R.string.Invalid_city_name;”更改为此“status=act.getString(R.string.Invalid_city_name)”;不转发。投票被否决并被标记为版主非常感谢,这很有效欢迎。请确保选择此答案作为解决方案,以表明此问题已得到回答。@NikolaiBuzovskiy