gpt4 book ai didi

java - put(String,long)找不到合适的方法怎么解决

转载 作者:搜寻专家 更新时间:2023-11-01 08:38:35 24 4
gpt4 key购买 nike

有人可以帮我解决这个问题吗?我正在尝试使用下面的代码将数据从 android 发送到 MySQL,但我得到了 error long cannot converted to String。我可以找到很多与 no suitable method found .put(String) 相关的解决方案,但我的情况不是这样,所以我决定从这里寻求帮助。任何帮助将不胜感激。

 public void addWorkForce(final String subcontractors, final String noPeople, final String noHours,final long twf)
{
class AddWorkForce extends AsyncTask<String, Void, String> {
ProgressDialog loading;

@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(WorkDetailsTable.this, "Please Wait",null, true, true);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}

@Override
protected String doInBackground(String... params) {

HashMap<String, String> data = new HashMap<String,String>();
data.put(Config.KEY_SUBCONTRACTORS,subcontractors);
data.put(Config.KEY_NUMBERPERSONS,noPeople);
data.put(Config.KEY_NUMBERHOURS,noHours);
data.put(Config.KEY_TWF,twf);
RequestHandler rh=new RequestHandler();
String result = rh.sendPostRequest(Config.ADD_WORKFORCE,data);
return result;
}
}

AddWorkForce ru = new AddWorkForce();
ru.execute(subcontractors,noPeople,noHours,twf);
}

错误

Error:(281, 21) error: no suitable method found for put(String,long)
method AbstractMap.put(String,String) is not applicable
(argument mismatch; long cannot be converted to String)
method HashMap.put(String,String) is not applicable
(argument mismatch; long cannot be converted to String)

最佳答案

你的 HashMap<String, String>意味着它等待 String键和 String值(value)。您可以更改 HashMap<String, Long>或转换您的 longString使用方法:

String.valueOf(long);

关于java - put(String,long)找不到合适的方法怎么解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com