gpt4 book ai didi

java - 如何将字符串传递给另一个函数

转载 作者:行者123 更新时间:2023-12-01 09:06:12 25 4
gpt4 key购买 nike

我尝试创建一个具有 4 个属性的新的单独类来记录不同的事件,这在我的任务中创建一个新对象并分配不同的值。所以我可以更轻松地对其进行排序,因为我将不同的信息存储在对象的单独变量中。

但是我得到了

unkown class aLog.id aLog.status aLog.action aLog.time

methode call expected at Log();

我做错了什么?

 public class UpdatePro extends AsyncTask<String, String, String> {

String z = "";
Boolean isSuccess = false;


String DBcard = cardnumberbox.getText().toString();
String DBshelf = shelfnumberbox.getText().toString();



@Override
protected void onPreExecute() {
LStatus aLog = LStatus();
aLog.id="";
aLog.status="";
aLog.action="";
aLog.time="";
}

@Override
protected void onPostExecute(String r) {
Toast.makeText(CameraActivity.this, r, Toast.LENGTH_SHORT).show();
if (isSuccess == true) {

}

}

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

if (DBcard.trim().equals("") || DBshelf.trim().equals(""))
z = getString(R.string.Invalid_Credentials);
else {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = getString(R.string.Forbindelses_fejl);
} else {
String itemcard = DBcard;
{
if (itemcard.substring(0, 1).startsWith("K")) {
itemcard = itemcard.substring(1);
} else {
itemcard = itemcard;//.substring(0));
}
}
String itemshelf = DBshelf;
{
if (itemshelf.substring(0, 1).startsWith("R")) {
itemshelf = "" + itemshelf.substring(1);
} else {
itemshelf = "" + itemshelf;//.substring(0));
}
}
String doerTicket;
doerTicket = setingPreferences.getString("doerTicket", "");
String sql =
"SET NOCOUNT ON; " +
"DECLARE @upd INT; " +
"EXEC [file].[usp_assignPartToShelf] " +
"@p_ItemNumber=?, " +
"@p_ShelfNumber=?, " +
"@p_UpdatedItems=@upd OUTPUT, " +
"@p_DoerTicket=?;" +
"SELECT @upd AS UpdatedItems;";
try (PreparedStatement s = con.prepareStatement(sql)) {
s.setString(1, itemcard);
s.setString(2, itemshelf);
s.setString(3, doerTicket);
ResultSet rs = s.executeQuery(); // above T-SQL always returns at least one ResultSet
rs.next();
if (s.getMoreResults()) {
System.out.printf(
"INFO:%n" +
" A second ResultSet was found.%n" +
" The previous ResultSet was returned by the stored procedure.%n" +
" Getting next ResultSet ...%n",
"");
rs = s.getResultSet();
rs.next();
System.out.println(rs.getString(1));
if (rs.getString(1).equals("0")) {
z = getString(R.string.Update_succes);
isSuccess = true;
}

}
PreparedStatement preparedStatement = null;
String sqli = "select ID,ItemNumber,Trashed,Sold from [file].[Item] where [ItemNumber] =?";
preparedStatement = con.prepareStatement(sqli);
preparedStatement.setString(1, itemcard);
ResultSet rsS = preparedStatement.executeQuery();
while (rsS.next()) {
String P_id = rsS.getString("ID");
String Trashed = rsS.getString("Trashed");
String Sold = rsS.getString("Sold");

if(Trashed.equals("1.000000")) {
//for updating trash
CallableStatement cs = null;
String queryundo = "{ call [file].[usp_trashItem](?,?,?,?)} ";
cs = con.prepareCall(queryundo);
cs.setString(1, P_id); // p_ID
cs.setString(2, "U"); //p_Action(U for untrash T for Trash)
cs.setInt(3, 1); //p_Quantity
cs.setString(4, doerTicket); //p_DoerTicket
cs.executeUpdate();
z = getString(R.string.untrashed);
}
else if (Sold.equals("1.000000"))
{
z = getString(R.string.item_sold);

}
}
con.close();
rs.close();
rsS.close();
}
}
} catch (Exception ex) {
isSuccess = false;
z = getString(R.string.Exceptions) + "L2)";
Log.e("MYAPP", "exception", ex);
}
}
return z;
}
}

我的类(class)

package ominidata.ominidata;

import java.util.Date;
public class LStatus {
public String id;
public String action;
public String status;
public Date time;
public void setId(String id) {
this.id = id;
}

public String getId() {
return id;
}

public void setAction(String action) {
this.action = action;
}

public String getAction() {
return action;
}

public void setStatus(String status) {
this.status = status;
}

public String getStatus() {
return status;
}

public void setTime(Date time) {
this.time = time;
}

public Date getTime() {
return time;
}
}

最佳答案

运行时多态性在这里不符合条件,因为我看不到 LStatus 类的任何派生子类。将对象创建移至构造函数或 AsyncTask 的 preExecute 方法中。

使用下面的代码创建对象

LStatus aLog = LStatus();

还将变量的范围更新为公共(public)。

public class LStatus {
public String id;
public String action;
public String status;
public Date time;

关于java - 如何将字符串传递给另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41269652/

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