0

こんにちは、次のコードを使用しています。

public class InsertionExample extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8085/XcartLogin/services/Insertion?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";

private String selectedCountry = null;
private String selectedAnimal = null;

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

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spnMusketeers);


    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

    //Dynamically generate a spinner data 
    createSpinnerDropDown();

}

//Add animals into spinner dynamically
private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(dataAdapter);
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

}

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

        String selectedItem = parent.getItemAtPosition(pos).toString();

        //check which spinner triggered the listener

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo unameProp =new PropertyInfo();
        unameProp.setName("userName");//Define the variable name in the web service method
       unameProp.setValue(selectedItem);//Define value for fname variable
        unameProp.setType(String.class);//Define the type of the variable
        request.addProperty(unameProp);


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

          try{
           androidHttpTransport.call(SOAP_ACTION, envelope);
              SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

             TextView result = (TextView) findViewById(R.id.textView2);
              result.setText(response.toString());

       }
       catch(Exception e){

       } 

        }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
    }

ここにステータスのリストがあります。ここでは以下のコードを使用します。

   List<String> list = new ArrayList<String>();
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

ここでアプリを実行すると、最初に Q が常にデータベースに表示されることを意味します...選択した値のみがデータベースに挿入された後。ここで、上記のコードリンクを変更する必要がある場合、これは List<String> list = new ArrayList<String>(); list.add("p"); list.add("Q");、アプリを実行する必要があることを意味します。つまり、最初にデータベースに P が常に表示されることを意味します...選択した値のみがデータベースに挿入された後、助けてください..なぜ最初に表示するのか私の最初のリストは常に私のデータベースにあります...これに対する解決策を教えてください。

Android アプリを実行する必要がある場合、Apache コンソール出力を取得した時間は次のとおりです。

  [ERROR] 2
   java.lang.ArrayIndexOutOfBoundsException: 2
at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:639)
at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:206)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

これは私のWebサービスコードです:

   public class Insertion {

    public String insertData(String userName,String userPassword){

   try{

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
     PreparedStatement statement =  con.prepareStatement("INSERT INTO xcart_orders(status) VALUES ('"+userName+"');");
     int result = statement.executeUpdate();
     }

     catch(Exception exc){
     System.out.println(exc.getMessage());
     }

    return "Insertion successfull!!";
     }

     }
4

1 に答える 1

0

onitemselected メソッド内で自分の SOAP を呼び出すので、ボタンを作成して SOAP を追加すると現在の値を取得できなかったのはそのためです。今、私は出力を得ました。

于 2012-08-29T10:16:01.023 に答える