0

さて、私は本当にここで立ち往生しています! 私は多くの方法でそれを試しましたが、無駄です。エミュレーターで起動した Android アプリケーションを介して wcf Web サービス (ローカル) にアクセスしようとしていますが、アプリがクラッシュします。コードは次のとおりです。

これは私のアンドロイドです

      public class MainActivity extends TabActivity {

        /* I am not sure about these !! SOry */ 
 private static final String SOAP_ACTION = "http://localhost:1034/ILocation_Based_Reminder_WCF/getReminder";
 private static final String METHOD_NAME = "getReminder";
 private static final String NAMESPACE = "http://localhost:1034/";
 private static final String URL = "http://localhost:1034/Location_Based_Reminder_WCF.svc/";




@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


private void initialize()
{
    try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

           // request.addProperty("3235466455");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);


            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try{
            androidHttpTransport.call(SOAP_ACTION, envelope);
            }catch(Exception e){
                System.out.println("this is the message");
                System.out.println(e.getMessage());
                System.out.println("this is stack tracer");
                e.printStackTrace();
            }

            SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

            String resultData = result.toString();

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

それがウェブサービス

インターフェース

namespace Location_Based_Reminder
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ILocation_Based_Reminder_WCF" in both code and config file together.
    [ServiceContract]
    public interface ILocation_Based_Reminder_WCF
    {
        [OperationContract]
        String insertUser(long user);
        [OperationContract]
        String insertReminder(long user,String Location,String Time,String Time_Offset,String Date,String Date_Offset,int Status,String Description);
        [OperationContract]
        String getReminder(long userMSISDN);

    }
}

.svc ファイル

namespace Location_Based_Reminder
{
     public class Location_Based_Reminder_WCF : ILocation_Based_Reminder_WCF
    {
        private BUS _bus;
        private ValueObject _vo;
        private void _initiate()
        {
            _bus = new BUS();
            _vo = new ValueObject();
        }





        #region getReminder
        public String getReminder(long userMSISDN)
        {
            _initiate();
            DataTable _table = new DataTable();
            _table = _bus.getReminder(3235466455);
            String check=null;
            foreach (DataRow row in _table.Rows)
            {
                check = row["reminder_Location"].ToString();
            }
            return check;
        }
        #endregion
    }
}

そして、ここに私が受け取るメッセージがあります

03-29 20:02:42.245: I/System.out(2102): this is the message
03-29 20:02:42.245: D/AndroidRuntime(2102): Shutting down VM
03-29 20:02:42.245: W/dalvikvm(2102): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-29 20:02:42.255: E/AndroidRuntime(2102): FATAL EXCEPTION: main
03-29 20:02:42.255: E/AndroidRuntime(2102): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.locationbasedreminderversionOne.Two/com.example.locationbasedreminderversionOne.Two.MainActivity}: java.lang.NullPointerException
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.os.Looper.loop(Looper.java:137)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at java.lang.reflect.Method.invoke(Method.java:511)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at dalvik.system.NativeStart.main(Native Method)
03-29 20:02:42.255: E/AndroidRuntime(2102): Caused by: java.lang.NullPointerException
03-29 20:02:42.255: E/AndroidRuntime(2102):     at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at com.example.locationbasedreminderversionOne.Two.MainActivity.initialize(MainActivity.java:116)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at com.example.locationbasedreminderversionOne.Two.MainActivity.onCreate(MainActivity.java:40)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.Activity.performCreate(Activity.java:5104)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-29 20:02:42.255: E/AndroidRuntime(2102):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-29 20:02:42.255: E/AndroidRuntime(2102):     ... 11 more

Androidマニフェストに権限などを追加しました。助けてください。前もって感謝します

4

3 に答える 3

0

ここでの問題は、設計したサービスから SOAP を取得する必要があることです。サンプルコードは以下の通り。

       String SOAP_ACTION = "http://tempuri.org/WriteToDB";
       String NAMESPACE = "http://tempuri.org/";
       String METHOD_NAME = "WriteToDB";
       String URL = "http://10.224.185.37/AndroidService.asmx?op=WriteToDB";
于 2013-03-31T14:46:57.923 に答える
0

Androidにネットワーク通信が含まれている場合はいつでも、onCreateメソッドで直接行うべきではありません。このAsyncアクティビティを使用する必要があるためです。

于 2013-04-03T16:37:24.273 に答える
0

anddoir コードの「localhost」は、Android のローカルホストを参照します。10.0.2.2 は、コンピューターのローカルホストの仮想 IP です ;-)

于 2013-04-10T20:14:46.600 に答える