登录Web服务异常(716):java.lang.ArrayIndexOutOfBoundsException:长度= 0;指数= 0 [英] Login Web Service Exception(716): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

查看:480
本文介绍了登录Web服务异常(716):java.lang.ArrayIndexOutOfBoundsException:长度= 0;指数= 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  **** Android的一面:**
        权限也被添加在Android中mainfest.xml
        ** webMethod.java ****
SoapObject要求=新SoapObject(SOAPNAMESPACE,SOAPLOGINMETHOD);
request.addProperty(用户名,用户名);
request.addProperty(密码,密码);
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = TRUE;
    envelope.setOutputSoapObject(请求);
    Log.d(参数OUT,+ envelope.bodyOut.toString());
    尝试{HttpTransportSE httpTransport =新HttpTransportSE(SOAPURL);
    httpTransport.call(SOAPLOGINACTION,信封);
    SoapObject响应=(SoapObject)envelope.bodyIn;
    Log.d(参数,+ envelope.bodyIn);
    ID = response.getProperty(0)的ToString();**** DOTNETWEBSERVICE方:**
 [的WebMethod]
公共字符串LoginCheck(用户名字符串,字符串密码)// INT waitId,串phoneName,串phoneStatus,字符串时,字符串日期)
{
    字符串userID1 = NULL;
    INT D = 0,DS = 0;
    字符串路径=数据源= UX-PC;初始目录= ResturantOrdingSystem;用户ID = SA;密码= 123;
    SqlConnection的CON =新的SqlConnection(路径);
    尝试
    {con.Open(); }
    赶上(例外EXX){}
    //字符串SQL =SELECT * FROM HR其中,username ='+用户名+'和密码='+密码+';
    字符串SQL =SELECT * FROM HR凡位置='服务员'和用户名='+用户名+'和密码='+密码+';
    // +'AND位置=服务员'    CMD的SqlCommand =新的SqlCommand(SQL,CON);
    博士= CMD.ExecuteReader();    而(dr.Read())
    {
        userID1 =(字符串)博士[名称];
    } con.Close();

问题:
我得到这个例外

  logtrace:异常(716):java.lang.ArrayIndexOutOfBoundsException:长度= 0;指数= 0
我使用kso​​ap2-机器人组装-2.6.0-JAR-具有依赖性
请形​​容我告诉我的解决方案?


解决方案

我觉得你的响应对象是空的,当您尝试将其指定为ID变量它给这个错误

  ID = response.getProperty(0)的ToString();

检查响应为空或不是?
检查你的web方法的SQL查询返回的数据?

    ****android side:**
        Permission is also added in Android mainfest.xml    
        **webMethod.java****
SoapObject request = new SoapObject(SOAPNAMESPACE,SOAPLOGINMETHOD);
request.addProperty("Username",Username);
request.addProperty("Password",Password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    Log.d("parameter out",""+ envelope.bodyOut.toString());
    try{HttpTransportSE httpTransport = new HttpTransportSE(SOAPURL);
    httpTransport.call(SOAPLOGINACTION, envelope);
    SoapObject response=(SoapObject) envelope.bodyIn;
    Log.d("parameter in",""+ envelope.bodyIn);
    id=response.getProperty(0).toString();

****DOTNETWEBSERVICE side:**
 [WebMethod]
public string LoginCheck(string username, string password)//,int waitId,string phoneName,string phoneStatus,string time,string date)
{
    string userID1 = null;
    int d = 0,ds=0;
    string path = "Data Source=UX-PC;Initial Catalog=ResturantOrdingSystem;User ID=sa;Password=123";
    SqlConnection con = new SqlConnection(path);
    try
    { con.Open(); }
    catch (Exception exx) { }
    //  string sql = "SELECT * FROM HR Where username='" + username + "'AND password='" + password + "'";
    string sql = "SELECT * FROM HR Where position='waiter' AND username='" + username + "'AND password='" + password + "'";
    //+ "'AND position=waiter'"

    SqlCommand CMD = new SqlCommand(sql, con);
    dr = CMD.ExecuteReader();

    while (dr.Read())
    {
        userID1 = (string)dr["name"];
    } con.Close();         

Problem: I am getting this exception in

logtrace: Exception(716): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 
i am using ksoap2-android-assembly-2.6.0-jar-with-dependencies
Please describe me tell me solution?

解决方案

I think your response object is empty, when you try to assign it to "id" variable it gives this error

id=response.getProperty(0).toString();

Check your response is null or not ? Check your web method sql query that it returns data ?

这篇关于登录Web服务异常(716):java.lang.ArrayIndexOutOfBoundsException:长度= 0;指数= 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆