2014-03-07 321 views
0

我創建了一個asp.net網絡服務和使用模擬器,我可以很容易地訪問我想要的網絡服務,現在我想通過網絡訪問網絡服務,所以我的手機將成爲客戶端和我的筆記本電腦將服務器試圖做很多小時,但沒有發生任何事情仍然給我java.lang.NullPointerException。 我創建了一個本地網絡和看圖片,看網絡信息http://s9.postimg.org/k3a7t754f/image.png,當我在手機連接到網絡我的IP地址是192.168.173.205通過網絡訪問網絡服務

  • 這是我的第一類UserService這個類將調用從AsyncTaskclass

    @Override 
    protected User doInBackground(Void... params) 
    { 
        try 
        { 
         return new UserService("CheckFirstTimeLogin", "UserApi.asmx") 
           .CheckLogin(mUsername, mPassword); 
        } 
        catch (Exception e) 
        { 
         return null; 
        } 
    } 
    
    @Override 
    protected void onPreExecute() 
    { 
        super.onPreExecute(); 
        alertDialog = new AlertDialog.Builder(LoginActivity.this).create(); 
    } 
    
    @Override 
    protected void onPostExecute(User user) 
    { 
        if (user == null) 
        { 
         onCancelled(); 
         alertDialog.setTitle(R.string.login_connecnt_title); 
         alertDialog.setMessage("خطأ اثناء عملية الإتصال"); 
         alertDialog.show(); 
        } 
    } 
    

package com.routingware.services;  
import android.util.Log; 

import com.routingware.database.models.User; 
import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.PropertyInfo; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

public String NAMESPACE = "http://tempuri.org/"; 
public String METHOD = ""; 
public String ACTION = ""; 
public String URL  = "http://192.168.173.1/projectnetwork/"; 

public class UserService extends CommonClass { 

    public UserService (String MethodName, String PageName) { 
     METHOD = MethodName; 
     ACTION = NAMESPACE + MethodName; 
     URL = URL + PageName; 
    } 

    public User CheckLogin (String Username, String Password) { 

     User user = null; 

     SoapObject Request = new SoapObject(NAMESPACE, METHOD); 

     // Send Username as parameter 
     PropertyInfo Pi = new PropertyInfo(); 
     Pi.setName("Username"); 
     Pi.setValue(Username); 
     Pi.setType(String.class); 
     Request.addProperty(Pi); 

     // Send Password as parameter 
     Pi = new PropertyInfo(); 
     Pi.setName("Password"); 
     Pi.setValue(Password); 
     Pi.setType(String.class); 
     Request.addProperty(Pi); 

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

     envelope.addMapping(NAMESPACE, "User",new User().getClass()); 
     HttpTransportSE httpTransport = new HttpTransportSE(URL); 
     httpTransport.debug = true; 

     try 
     { 
      Log.e("call","1"); 
      httpTransport.call(ACTION, envelope); 
      SoapObject Response = (SoapObject)envelope.getResponse(); 

      user = new User(); 
      user.setUserID(Integer.parseInt(Response.getProperty(0).toString())); 
      user.setUserName(Response.getProperty(1).toString()); 
      user.setUserPasswrd(Response.getProperty(2).toString()); 
      user.setBranchID(Integer.parseInt(Response.getProperty(3).toString())); 
      user.setCompanyID(Integer.parseInt(Response.getProperty(4).toString())); 
      user.setUserState(Boolean.parseBoolean(Response.getProperty(5).toString())); 
     } 
     catch (Exception ex) 
     { 
      Log.e("call",ex.toString()); 
      return null; 
     } 
     finally 
     { 
      return user; 
     } 
    } 
} 
  • 呼叫的方法

    對不起我的英文不好

  • 回答

    0

    你能發表日誌嗎?您的設備是否連接到筆記本電腦所連接的同一個無線網絡。 由於您使用本地網絡作爲您的服務,設備應連接到相同的WiFi網絡。

    +0

    是連接到同一個wifi網絡 – user3367149

    +0

    791-804的步驟是ksoap2 /com.routingware.app E/call:java.lang.NullPointerException – user3367149

    +0

    你可以發佈你得到的所有錯誤日誌嗎? –