我在使用我通过datasnap在Delphi中创建的webservice时,在android 4.0版本中出现错误,在android 2.0版本中运行流畅,在4.0版本中更多生成异常,不知道为什么 “javaandroid. DBX 异常”
我在 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;
在生成 embarcadero 的 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();
}
}
谁能帮我做到这一点?
谢谢你。
日志猫
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);
谢谢你