onCreate()
在我尝试在我的onCreate()
方法
之外设置适配器之前,我得到了这个异常系统服务不可用于活动。
我尝试过使用runOnUIThread()
函数,但仍然无法解决我的问题。
这实际上是我的代码。
我正在通过一种方法将我的服务子类中的列表发送到我的活动类。
Class KitchenSerivce extends Service
@Override
public int onStartCommand(Intent intent, int flags , int startId)
{
super.onStartCommand(intent, flags, startId);
Toast.makeText(this, "Service started ...", Toast.LENGTH_SHORT).show();
try
{
SoapObject result=null;
SoapObject request=new SoapObject(NAME_SPACE, METHOD_NAME);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
try
{
HttpTransportSE androidHttpTransportSE=new HttpTransportSE(URL, 5000);
androidHttpTransportSE.call(SOAP_ACTION, envelope);
result=(SoapObject)envelope.getResponse();
orderList=getOrder(result);
Log.v("Server response", result.toString());
}
catch (Exception e)
{
msg=Toast.makeText(this, "Connection to Server Failed", Toast.LENGTH_SHORT);
msg.show();
}
msg=Toast.makeText(this, result.toString(), Toast.LENGTH_SHORT);
msg.show();
KitchenManager kitchen=new KitchenManager();
kitchen.sendOrder(orderList);
}
catch (Exception e)
{
System.out.println("Exception Caught:"+e.getMessage());
}
return START_STICKY;
}
KitchenManager 扩展了 Activity
public void sendOrder(List<Order> orderList)
{
this.orderList=orderList;
for(int i=0;i<orderList.size();i++)
{
System.out.println("List Size:"+orderList.size());
System.out.println("Item:"+orderList.get(i).getItem());
}
adapter=new OrdersAdapter(KitchenManager.this,R.layout.kitchen_order_list,this.orderList);
if(this.orderList.size()==0)
{
}
else
{
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
我sendOrder()
在网上的公共无效中遇到异常
adapter=new OrdersAdapter(KitchenManager.this,R.layout.kitchen_order_list,this.orderList);
请如果有人可以帮助我,因为我已经完成搜索但无法找到解决我的问题的方法。提前致谢。