3

ここに投稿する前に多くの選択肢を確認しました。
なぜこのエラーがUnKnownHost Exception発生するのかわかりません。誰かが解決策を教えてください。

MyCallingクラス

public class AndroidLoginExampleActivity extends Activity 
{
    private static final String SOAP_ACTION ="urn:Mage_Api_Model_Server_HandlerAction";
    private static final String NAMESPACE = "urn:Magento";
    private  static final String Method_Name="login";
    private static final String URL ="http://cws24/machinetest/api/?wsdl";

    TextView tv;
    Context mContext;
    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.tv_status);

    SoapObject request = new SoapObject(NAMESPACE,Method_Name);
    request.addProperty("username", "android");
    request.addProperty("apiKey", "android");

    SoapSerializationEnvelope envelopes = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);
    envelopes.dotNet = false;
    envelopes.setOutputSoapObject(request);
    mContext=AndroidLoginExampleActivity.this;
    try 
    {
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
        androidHttpTransport.debug =true;
        androidHttpTransport.call(SOAP_ACTION, envelopes);//Getting the Exception here
        SoapPrimitive resultString=(SoapPrimitive)envelopes.getResponse();
        tv.setText("Status "+resultString);
        new AlertDialog.Builder(mContext).setMessage(""+resultString).show();
    } 
    catch (Exception e) {e.printStackTrace();
    new AlertDialog.Builder(mContext).setMessage(""+e.toString()).show();
    }   
}
}  

ログ出力::

07-17 02:20:43.376: WARN/System.err(25212): java.net.UnknownHostException: Host is unresolved: cws24:80
07-17 02:20:43.416: WARN/System.err(25212):     at java.net.Socket.connect(Socket.java:1037)
07-17 02:20:43.466: WARN/System.err(25212):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
07-17 02:20:43.486: WARN/System.err(25212):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
07-17 02:20:43.496: WARN/System.err(25212):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
07-17 02:20:43.496: WARN/System.err(25212):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
07-17 02:20:43.496: WARN/System.err(25212):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
07-17 02:20:43.496: WARN/System.err(25212):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46)
07-17 02:20:43.506: WARN/System.err(25212):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68)
07-17 02:20:43.506: WARN/System.err(25212):     at com.magento.example.AndroidLoginExampleActivity.onCreate(AndroidLoginExampleActivity.java:44)
07-17 02:20:43.506: WARN/System.err(25212):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-17 02:20:43.506: WARN/System.err(25212):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-17 02:20:43.516: WARN/System.err(25212):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-17 02:20:43.516: WARN/System.err(25212):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-17 02:20:43.516: WARN/System.err(25212):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-17 02:20:43.546: WARN/System.err(25212):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 02:20:43.546: WARN/System.err(25212):     at android.os.Looper.loop(Looper.java:123)
07-17 02:20:43.556: WARN/System.err(25212):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-17 02:20:43.556: WARN/System.err(25212):     at java.lang.reflect.Method.invokeNative(Native Method)
07-17 02:20:43.567: WARN/System.err(25212):     at java.lang.reflect.Method.invoke(Method.java:521)
07-17 02:20:43.567: WARN/System.err(25212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-17 02:20:43.576: WARN/System.err(25212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-17 02:20:43.576: WARN/System.err(25212):     at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2

2

SOAPAPIからXMLRPCAPIの使用法に移行することで、私の問題は解決しました。
以下は私が XMLRPCを使用したコードです

あなたはそのためDownLoadXMLRPC図書館に行かなければなりません。

Android用のXMLRPCライブラリをダウンロードするには、ここをクリックしてください

package org.xmlrpc;

import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Test extends Activity {


    String sessionId ="";
    ProgressDialog pd;
    Context mContext;
    EditText username,apikey;
    Button login;


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


       username=(EditText)findViewById(R.id.username);
       apikey=(EditText)findViewById(R.id.apikey);
       login=(Button)findViewById(R.id.login);
   }
   public void checkUser(View v) 
   {
       if(username.getText().toString().equals("") || apikey.getText().toString().equals(""))
       {
           if(username.getText().toString().equals(""))
           {
               username.requestFocus();
           }
           else
           {
               apikey.requestFocus();
           }
           Toast.makeText(mContext, "Please fill this empty field", Toast.LENGTH_LONG).show();
        }
       else
       {
           new DownloadWebPageTask().execute();   
       }
    }

   private class DownloadWebPageTask extends AsyncTask<Void, Integer, Void> {
       @Override
          protected void onPreExecute() 
          {
                pd=ProgressDialog.show(mContext, "", "Please Wait...\nLoading data...", false);
          }
          @Override
          protected void onPostExecute(Void v) 
          {
              if(pd.isShowing())
                    {
                       pd.dismiss();
                    }
            if(sessionId.equals(""))
            {
                Toast.makeText(mContext, "in Correct Details..Please try again", 
                        Toast.LENGTH_LONG).show();
            }
            else
            {
                Utils.sessionId=sessionId;
                startActivity(new Intent(mContext,Dashboard.class));
                finish();   
            }

          }


       @Override
       protected Void doInBackground(Void... arg0) 
       {
           XMLRPCClient client = new XMLRPCClient( "http://192.168.1.237/machinetest/index.php/api/xmlrpc");
           try 
           {
                   sessionId = (String)client.call( "login", username.getText().toString(),
                           apikey.getText().toString());
                   Log.d( "MY_XMLRPC_SUCCESS_SESSION_ID", sessionId);
           }
           catch (XMLRPCException e) 
           {
               Log.d( "APP_INFO ",  "Exception:  " + e.getMessage());
               Log.e( "APP_INFO ",  "Exception:  " + e.toString());
           }     
           return null;
       }
   }
}
于 2012-07-23T10:43:21.837 に答える
0

URLが正しいかどうかを確認する必要があります。

于 2012-07-18T07:46:02.090 に答える