首页 \ 问答 \ android中的ksoap2异常处理(ksoap2 exception handling in android)

android中的ksoap2异常处理(ksoap2 exception handling in android)

我在以下代码中遇到异常

                package com.dipl.smpm.smpm;

 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapPrimitive;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.AndroidHttpTransport;
 import org.ksoap2.transport.HttpTransport;

 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.TextView;
 import android.widget.Toast;
public class ConnectHttp extends Activity {
    private static final String SOAP_ACTION = "http://tempuri.org/loginDetails";
    private static final String METHOD_NAME = "loginDetails";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://localhost:88/EmpService.asmx";
    TextView tv;
 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.textView11);
    SoapObject sobj_requestLogin=new SoapObject(NAMESPACE, METHOD_NAME);
    sobj_requestLogin.addProperty("username", "a");
    sobj_requestLogin.addProperty("password", "a");
    SoapSerializationEnvelope spenve_Login = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    spenve_Login.dotNet=true;
    spenve_Login.setOutputSoapObject(sobj_requestLogin);

    AndroidHttpTransport htrans_login= new AndroidHttpTransport(URL);

    try{
        Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
        htrans_login.call(SOAP_ACTION,spenve_Login);
        Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
        SoapPrimitive spprim_login=(SoapPrimitive)spenve_Login.getResponse();
        Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
        tv.setText("result: "+spprim_login+" ");
        Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show();
    }
    catch(Exception e){
        Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
    }


}
 }

我成功地举杯祝酒,但是在吐司'2'来临之前,它会立刻进入'异常'吐司。 帮帮我,我的错误是什么? 我也使用2.3 ksoap2 2.3 jar作为用户定义的lib。


I'm getting exception in the following code

                package com.dipl.smpm.smpm;

 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapPrimitive;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.AndroidHttpTransport;
 import org.ksoap2.transport.HttpTransport;

 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.TextView;
 import android.widget.Toast;
public class ConnectHttp extends Activity {
    private static final String SOAP_ACTION = "http://tempuri.org/loginDetails";
    private static final String METHOD_NAME = "loginDetails";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://localhost:88/EmpService.asmx";
    TextView tv;
 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.textView11);
    SoapObject sobj_requestLogin=new SoapObject(NAMESPACE, METHOD_NAME);
    sobj_requestLogin.addProperty("username", "a");
    sobj_requestLogin.addProperty("password", "a");
    SoapSerializationEnvelope spenve_Login = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    spenve_Login.dotNet=true;
    spenve_Login.setOutputSoapObject(sobj_requestLogin);

    AndroidHttpTransport htrans_login= new AndroidHttpTransport(URL);

    try{
        Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
        htrans_login.call(SOAP_ACTION,spenve_Login);
        Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
        SoapPrimitive spprim_login=(SoapPrimitive)spenve_Login.getResponse();
        Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
        tv.setText("result: "+spprim_login+" ");
        Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show();
    }
    catch(Exception e){
        Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
    }


}
 }

i'm getting a toast '1' sucessfully but its going to 'exception' toast immediately before toast '2' comes. help me what is my mistake? also i'm using 2.3 ksoap2 2.3 jar as user defined lib.


原文:https://stackoverflow.com/questions/17448036
更新时间:2022-03-23 08:03

最满意答案

如上所述,您无需将配置文件URL保存到数据库。 我猜所有的个人资料网址都会遵循一些标准格式(即www.example.com/profile.php?id=1 )?

好吧,如果您保存了数据库中的所有内容,然后您决定将格式更改为类似于www.example.com/profile/1那么您将拥有大量过时的数据。你的数据库。 您将不得不浏览每条记录并更新它,这对数据库表来说可能是危险的,比如数百万行。

因此,解决方案是使用带参数的脚本。 说profile.php 。 如上所述,您将使用$_GET数组中的数据检查配置文件:

<?php
if (isset($_GET['id'])) {
    $id  = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT * FROM members WHERE id = '$id' LIMIT 1";
    $res = mysql_query($sql);
    if (mysql_num_rows() > 0) {
        $member = mysql_fetch_object($res);
        // handle displaying of member's profile here
    }
    else {
        // member does not exist with ID
    }
}
?>

这样,如果您决定更改脚本名称或使用搜索引擎友好的URL,则无需更改数据库结构。


As stated above, you don't need to save a profile URL to the database. I'm guessing all profile URLs are going to follow some standard form (i.e. www.example.com/profile.php?id=1)?

Well, if you saved all of those in your database and then you decided you were going to change the format to something like www.example.com/profile/1 you're going to have a lot of out-of-date data in your database. You're going to have to go through each record and update it, and that could be dangerous on a database table with say, millions of rows.

Therefore, the solution is to have a script that takes a parameter. Say profile.php. As above, you would check for the profile using the data in the $_GET array:

<?php
if (isset($_GET['id'])) {
    $id  = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT * FROM members WHERE id = '$id' LIMIT 1";
    $res = mysql_query($sql);
    if (mysql_num_rows() > 0) {
        $member = mysql_fetch_object($res);
        // handle displaying of member's profile here
    }
    else {
        // member does not exist with ID
    }
}
?>

That way, if you decide to change the script name or use search engine-friendly URLs, you don't need to change your database structure.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。