ユーザー名、パスワードをmysqlサーバーを介して確認しようとしていますが、同じコードは次のとおりです。
以下のコードに示すように、php で Web サービスを作成し、名前空間とその他の値について説明しました。
package com.example.androidloginexampleactivity;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AndroidLoginExampleActivity extends Activity {
private TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_login_example);
Button login = (Button) findViewById(R.id.btn_login);
//this.accessWebService(textView);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
LoginAction lgn = new LoginAction();
lgn.execute();
}
});
}
private class LoginAction extends AsyncTask<String, Void, String>
{
protected String doInBackground(String... urls)
{
String webResponse = "";
try{
final String NAMESPACE = "urn:stockserver";
final String URL = "http://localhost/stockserver1.php?wsdl";
//private final String URL = " http://10.0.2.2:8080/WebApplication2/Login?Tester";
final String SOAP_ACTION = "urn:stockserver#getStockQuote";
final String METHOD_NAME = "getStockQuote";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText userName = (EditText) findViewById(R.id.tf_userName);
String user_Name = userName.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.tf_password);
String user_Password = userPassword.getText().toString();
//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("userName");//Define the variable name in the web service method
unameProp.setValue(user_Name);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass propert ies to the variable
//Pass value for Password variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
TextView result1 = (TextView) findViewById(R.id.tv_status);
result1.setText(response.toString());
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),"Completed...", Toast.LENGTH_LONG).show();
}
return webResponse;
}
protected void onPostExecute(String result) {
textView.setText(result);
Toast.makeText(getApplicationContext(),"Completed...", Toast.LENGTH_LONG).show();
}
}
私が得ている次のエラー:
10-08 12:51:28.639: W/dalvikvm(2245): threadid=13: thread exiting with uncaught exception (group=0x40a71930)
10-08 12:51:28.749: E/AndroidRuntime(2245): FATAL EXCEPTION: AsyncTask #3
10-08 12:51:28.749: E/AndroidRuntime(2245): java.lang.RuntimeException: An error occured while executing doInBackground()
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.lang.Thread.run(Thread.java:856)
10-08 12:51:28.749: E/AndroidRuntime(2245): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.os.Handler.<init>(Handler.java:197)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.os.Handler.<init>(Handler.java:111)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.widget.Toast$TN.<init>(Toast.java:324)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.widget.Toast.<init>(Toast.java:91)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.widget.Toast.makeText(Toast.java:238)
10-08 12:51:28.749: E/AndroidRuntime(2245): at com.example.androidloginexampleactivity.AndroidLoginExampleActivity$LoginAction.doInBackground(AndroidLoginExampleActivity.java:92)
10-08 12:51:28.749: E/AndroidRuntime(2245): at com.example.androidloginexampleactivity.AndroidLoginExampleActivity$LoginAction.doInBackground(AndroidLoginExampleActivity.java:1)
10-08 12:51:28.749: E/AndroidRuntime(2245): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-08 12:51:28.749: E/AndroidRuntime(2245): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-08 12:51:28.749: E/AndroidRuntime(2245): ... 4 more
これを解決するのを手伝ってください、事前に感謝します....