gpt4 book ai didi

java - 无法收集 java/android 中 int 数组的值

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

我正在尝试通过使用它来收集 int 数组中的一些值,这些值来自 Web 服务。这里我使用 SOAP 方法进行消费。

当我尝试收集 int 数组中的值时,我无法运行模拟器。

如何克服这个错误?请找到我的来源以供引用。

Main_WB.java

 public class Main_WB extends Activity 
{
EditText edt1,edt2;
TextView txt_1;
Button btn;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

edt1 = (EditText)findViewById(R.id.editText1);
edt2 = (EditText)findViewById(R.id.editText2);
btn = (Button)findViewById(R.id.button1);

btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(),edt2.getText().toString());
}
});
}

private void getTMSChart(String FromDate,String ToDate)
{
txt_1 = (TextView)findViewById(R.id.textView1);

System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.dotNet = true;

String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";

SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);

envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);

SoapObject result = (SoapObject) envelope.bodyIn;

SoapObject root = (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");

int tablesCount = root.getPropertyCount();


for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();

for (int j = 0; j < propertyCount; j++)
{

// String orderNo = table.getPropertyAsString("Order_No");
// String freight = table.getPropertyAsString("Freight_Rate");
// String percent = table.getPropertyAsString("Margin_Percent");


int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));

int[] ord = new int[orderNo];
int[] frei = new int[freightRate];
int[] margin = new int[marginPercent];


// whatever you do with these values

txt_1.setText(ord);
txt_1.setText(frei);
txt_1.setText(margin);
}
}
}
catch (Exception e)
{
}
} }

最佳答案

这是一个编译错误,并且该错误是不言自明的:

The method setText(CharSequence) in the type TextView is not applicable for the arguments (int[])

这意味着方法 setText() 的参数必须为 CharSequence 类型,但您使用 int[] 类型的参数调用它,其中不是 CharSequence。

int[] 数组转换为字符串,并且当 String 实现 CharSequence 时,将结果字符串传递给 setText()。例如:

txt_1.setText(Arrays.toString(ord));

此外,我真的不明白在同一文本字段上使用三个不同参数调用 setText() 有什么意义。

关于java - 无法收集 java/android 中 int 数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12582556/

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