2

Delphiでdatasnapによって作成したWebサービスを使用すると、バージョン4.0でエラーが発生します。バージョン2.0ではAndroidがスムーズに実行され、バージョン4.0では例外が生成されます。理由がわかりません 。 DBXException」

Delphiでの私の選択

   function TServerMethods1.GetDados_Clientes(Codigo: string; out Nome: string): string;
    var
     sSQL: string;
     begin
        sSQL := ' SELECT CAST(CODIGO AS VARCHAR(30))AS CODIGO, NOME '+
           '   FROM CLIENTES '+
           '  WHERE ATIVO = ''Sim'' '+
           '  AND CAST(CODIGO AS VARCHAR(30)) = '+ QuotedStr(Codigo);  

        with CDS_Tabelas do
        begin
          Close;
          CommandText := sSQL;
          Open;
          Nome := FieldByName('CODIGO').AsString + ' - ' +  FieldByName('NOME').AsString;
          Result := Nome;
        end;
      end;

エンバカデロを生成するJavaプロキシクラスでは、このメソッド

  public static class GetDados_ClientesReturns {
     public String Nome;
     public String returnValue;
  }

  public GetDados_ClientesReturns GetDados_Clientes(String Codigo)
        throws DBXException {
     DSRESTCommand cmd = getConnection().CreateCommand();
     cmd.setRequestType(DSHTTPRequestType.GET);
     cmd.setText("TServerMethods1.GetDados_Clientes");
     cmd.prepare(get_TServerMethods1_GetDados_Clientes_Metadata());
     cmd.getParameter(0).getValue().SetAsString(Codigo);
     getConnection().execute(cmd);
     GetDados_ClientesReturns ret = new GetDados_ClientesReturns();
     ret.Nome = cmd.getParameter(1).getValue().GetAsString();
     ret.returnValue = cmd.getParameter(2).getValue().GetAsString();
     return ret;
  }

私はAsyncTaskを使用するように話しました。、しかし私はコードを実行できませんでした

   public class BuscaCliente extends AsyncTask<Void, Void, Void> {

    private ProgressDialog progress;
    private Context context;

    protected void onPreExecute() {
        // Cria novo um ProgressDialogo e exibe
        progress = new ProgressDialog(context);
        progress.setMessage("Aguarde...");
        progress.show();

    }

    protected Void doInBackground(Void... arg0) {
        DSRESTConnection conn = getConnection();
        TServerMethods1 serv = new TServerMethods1(conn);

        try {
            String idCharCodItem = edtCliente.getText().toString();
            String[] idNumItem = idCharCodItem.split("-");

            GetDados_ClientesReturns ret;
            ret = serv.GetDados_Clientes(idNumItem[0]);

            if (ret.Nome.equals(" - ")) {
                Alerta.mostrarAtencao(VendaClienteActivity.this,
                        getString(R.string.msg_clientenaolocalizado), 0,
                        false);
                carregando(false);
                // permanece no mesmo focus
                edtCliente.setText("");
                edtCliente.setFocusableInTouchMode(true);
                edtCliente.requestFocus();

            } else {
                // parametro = 0 significa 'Não', 1 significa 'Sim'
                if (parametroBLOQUEIA_CLIENTE_S_REG_ENTR() == 1) {
                    // ai verifica se o cliente tem registro do entrada
                    if (verificaIDCliente() != Integer
                            .parseInt(idNumItem[0])) {
                        Alerta.mostrarAtencao(
                                VendaClienteActivity.this,
                                getString(R.string.msg_clientesemregentrada),
                                0, false);
                        carregando(false);

                        // permanece no mesmo focus
                        edtCliente.setText("");
                        edtCliente.setFocusableInTouchMode(true);
                        edtCliente.requestFocus();
                    } else {
                        mudaFocusCliente();
                        // recebe o nome e o id do cliente
                        edtCliente.setText(ret.Nome);
                    }
                } else {
                    mudaFocusCliente();
                    // recebe o nome e o id do cliente
                    edtCliente.setText(ret.Nome);
                }
            }

        } catch (Exception e) {
            Toast.makeText(VendaClienteActivity.this, e.toString(),
                    Toast.LENGTH_LONG).show();
        }

        return null;
    }

    protected void onPostExecute(Void result) {
        progressDialog.dismiss();
    }

}

誰かが私がこれをするのを手伝ってもらえますか?

ありがとうございました。


Logcat

   01-12 07:54:38.139: D/AndroidRuntime(16712): Shutting down VM
   01-12 07:54:38.139: W/dalvikvm(16712): threadid=1: thread exiting with uncaught   exception (group=0x40018578)
   01-12 07:54:38.139: E/AndroidRuntime(16712): FATAL EXCEPTION: main
   01-12 07:54:38.139: E/AndroidRuntime(16712): java.lang.NullPointerException
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.app.Dialog.<init>(Dialog.java:141)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.app.AlertDialog.<init>(AlertDialog.java:63)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  br.com.azsolucoes.azcomanda.activities.VendaClienteActivity$BuscaCliente.onPreExecute(Venda       ClienteActivity.java:2061)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  android.os.AsyncTask.execute(AsyncTask.java:391)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  br.com.azsolucoes.azcomanda.activities.VendaClienteActivity.setFocusEdit(VendaClienteActivi       ty.java:285)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at br.com.azsolucoes.azcomanda.activities.VendaClienteActivity$7.onClick(VendaClienteActivity.       java:1026)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  android.view.View.performClick(View.java:2485)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  android.view.View$PerformClick.run(View.java:9080)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at  android.os.Handler.handleCallback(Handler.java:587)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.os.Handler.dispatchMessage(Handler.java:92)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.os.Looper.loop(Looper.java:130)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at android.app.ActivityThread.main(ActivityThread.java:3687)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at java.lang.reflect.Method.invokeNative(Native Method)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at java.lang.reflect.Method.invoke(Method.java:507)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
   01-12 07:54:38.139: E/AndroidRuntime(16712):     at dalvik.system.NativeStart.main(Native Method)

AsyncTaskなしでバージョン2.0のコードを使用します

 private void pesquisarClientes() {
    dialog = ProgressDialog.show(this, "Aguarde...",
            "Pesquisando registros.", false, true);
    dialog.setIcon(R.drawable.ic_launcher);
    dialog.setCancelable(false);

    DSRESTConnection conn = getConnection();
    TServerMethods1 serv = new TServerMethods1(conn);

    try {
        String idCharCodItem = edtCliente.getText().toString();
        String[] idNumItem = idCharCodItem.split("-");

        GetDados_ClientesReturns ret;
        ret = serv.GetDados_Clientes(idNumItem[0]);

        if (ret.Nome.equals(" - ")) {
            ShowMensagem.showMessage("Atenção!",
                    MensagensCentralizadas.msg_clientenaolocalizado, this);
            // permanece no mesmo focus
            edtCliente.setText("");
            edtCliente.setFocusableInTouchMode(true);
            edtCliente.requestFocus();

        } else {
            // parametro = 0 significa 'Não', 1 significa 'Sim'
            if (parametroBLOQUEIA_CLIENTE_S_REG_ENTR() == 1) {
                // ai verifica se o cliente tem registro do entrada
                if (verificaIDCliente() != Integer.parseInt(idNumItem[0])) {
                    ShowMensagem
                            .showMessage(
                                    "Atenção!",
                                    MensagensCentralizadas.msg_clientesemregentrada,
                                    this);
                    // permanece no mesmo focus
                    edtCliente.setText("");
                    edtCliente.setFocusableInTouchMode(true);
                    edtCliente.requestFocus();
                } else {
                    mudaFocusCliente();
                    // recebe o nome e o id do cliente
                    edtCliente.setText(ret.Nome);
                }
            } else {
                mudaFocusCliente();
                // recebe o nome e o id do cliente
                edtCliente.setText(ret.Nome);
            }
        }

        finalizaDialogo(false, "");
        // desabilita o dialog
        dialog.dismiss();
    } catch (Exception e) {
        // desabilita o dialog
        dialog.dismiss();
        finalizaDialogo(true, e.toString());
    }
}

このコードを使ってここに来ました

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    setContentView(R.layout.tela_vendacli);

    // versão 4.0 android
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);

ありがとうございました

4

1 に答える 1

0

彼の方法の声明では

function TServerMethods1.GetDados_Clientes(Codigo: string; out Nome: string): string;

結果がすでにある場合、文字列は out を使用する必要はありません。var として配置できる場合は必要ありません。

function TServerMethods1.GetDados_Clientes(Codigo: string; var Nome: string): string;

プロキシを再生成し、結果が null または nil にならないように注意してください。

プロキシは間違っていないか、間違えることはありませんが、TJsonObject に対して TJsonNull のキャストを作成することはできません。

于 2013-08-14T18:26:17.770 に答える