从另一个方法检索复选框时出错

时间:2014-10-21 17:22:58

标签: java android checkbox classcastexception

在我的方法中,我检查是否选中了复选框,复选框有我在创建TableLayout时给出的ID。

我收到了ClassCastException,这是我的错误:

10-21 15:08:41.458: E/AndroidRuntime(23500): FATAL EXCEPTION: AsyncTask #4
10-21 15:08:41.458: E/AndroidRuntime(23500): Process: com.example.controledeprodutosflorisa, PID: 23500
10-21 15:08:41.458: E/AndroidRuntime(23500): java.lang.RuntimeException: An error occured while executing
     

doInBackground()       10-21 15:08:41.458:E / AndroidRuntime(23500):在android.os.AsyncTask $ 3.done(AsyncTask.java:300)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.FutureTask.setException(FutureTask.java:222)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.FutureTask.run(FutureTask.java:242)       10-21 15:08:41.458:E / AndroidRuntime(23500):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.lang.Thread.run(Thread.java:841)       10-21 15:08:41.458:E / AndroidRuntime(23500):引起:java.lang.ClassCastException:android.widget.TextView无法强制转换   到android.widget.CheckBox       10-21 15:08:41.458:E / AndroidRuntime(23500):at diogo.florisa.levantamento.DetalheVersao.enviaDadosNewage(DetalheVersao.java:635)       10-21 15:08:41.458:E / AndroidRuntime(23500):at diogo.florisa.levantamento.DetalheVersao.access $ 0(DetalheVersao.java:562)       10-21 15:08:41.458:E / AndroidRuntime(23500):at diogo.florisa.levantamento.DetalheVersao $ Assincrono.doInBackground(DetalheVersao.java:1225)       10-21 15:08:41.458:E / AndroidRuntime(23500):at diogo.florisa.levantamento.DetalheVersao $ Assincrono.doInBackground(DetalheVersao.java:1)       10-21 15:08:41.458:E / AndroidRuntime(23500):在android.os.AsyncTask $ 2.call(AsyncTask.java:288)       10-21 15:08:41.458:E / AndroidRuntime(23500):at java.util.concurrent.FutureTask.run(FutureTask.java:237)       10-21 15:08:41.458:E / AndroidRuntime(23500):...还有4个       10-21 15:08:41.618:I / ActivityManager(23500):时间轴:Activity_idle id:android.os.BinderProxy@42bbcf10 time:22938961       10-21 15:08:41.939:E / WindowManager(23500):android.view.WindowLeaked:Activity   diogo.florisa.levantamento.DetalheVersao已经泄露了窗户   com.android.internal.policy.impl.PhoneWindow $ {DecorView 42e6b0e0   最初添加的V.E ..... R ...... D 0,0-880,192}       10-21 15:08:41.939:E / WindowManager(23500):在android.view.ViewRootImpl。(ViewRootImpl.java:377)       10-21 15:08:41.939:E / WindowManager(23500):在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)       10-21 15:08:41.939:E / WindowManager(23500):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)       10-21 15:08:41.939:E / WindowManager(23500):在android.app.Dialog.show(Dialog.java:296)       10-21 15:08:41.939:E / WindowManager(23500):at diogo.florisa.levantamento.DetalheVersao $ Assincrono.onPreExecute(DetalheVersao.java:1208)       10-21 15:08:41.939:E / WindowManager(23500):在android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)       10-21 15:08:41.939:E / WindowManager(23500):在android.os.AsyncTask.execute(AsyncTask.java:535)       10-21 15:08:41.939:E / WindowManager(23500):at diogo.florisa.levantamento.DetalheVersao $ 3.onClick(DetalheVersao.java:138)       10-21 15:08:41.939:E / WindowManager(23500):at com.android.internal.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:166)       10-21 15:08:41.939:E / WindowManager(23500):在android.os.Handler.dispatchMessage(Handler.java:102)       10-21 15:08:41.939:E / WindowManager(23500):在android.os.Looper.loop(Looper.java:136)       10-21 15:08:41.939:E / WindowManager(23500):在android.app.ActivityThread.main(ActivityThread.java:5103)       10-21 15:08:41.939:E / WindowManager(23500):at java.lang.reflect.Method.invokeNative(Native Method)       10-21 15:08:41.939:E / WindowManager(23500):at java.lang.reflect.Method.invoke(Method.java:515)       10-21 15:08:41.939:E / WindowManager(23500):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:790)       10-21 15:08:41.939:E / WindowManager(23500):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)       10-21 15:08:41.939:E / WindowManager(23500):at dalvik.system.NativeStart.main(Native Method)

有人能帮助我吗? (抱歉我的英语不好)

修改

在这里,我创建了tablelayout行并设置了checkbox id:

public String[][] getListaProdutos() {

      // Log.e("Versão:", versao);
      Banco b = new Banco(contextoApp, "Produtos.db", null, 1);
      Cursor c = b.getConnection().query("CONFERENCIA_COZINHA",
              new String[] { "DESCRICAO", "FISICO", "CODIGO", "VERSAO" },
              "VERSAO = ?", new String[] { versao }, "SUBSTR(CODIGO,1,14)",
              null, null);

      ArrayList<String[]> lista = new ArrayList<String[]>();
      if (c.moveToFirst()) {
          do {
              String[] aDado = new String[3];
              this.popularListaComProdutos(c.getString(0), c.getInt(1),
                      c.getString(2));
              aDado[0] = c.getString(0);
              aDado[1] = Integer.toString(c.getInt(1));
              aDado[2] = c.getString(2);
              lista.add(aDado);

          } while (c.moveToNext());
      }

      Cursor c1 = b.getConnection().query("CONFERENCIA_CORANTES",
              new String[] { "DESCRICAO", "FISICO", "CODIGO" }, "VERSAO = ?",
              new String[] { versao }, "SUBSTR(CODIGO,1,14)", null, null);

      if (c1.moveToFirst()) {
          do {
              String[] aDado = new String[3];
              this.popularListaComProdutos(c1.getString(0), c1.getInt(1),
                      c1.getString(2));
              aDado[0] = c1.getString(0);
              aDado[1] = Integer.toString(c1.getInt(1));
              aDado[2] = c1.getString(2);
              lista.add(aDado);

          } while (c1.moveToNext());
      }

      // Log.e("Retornos: ", Integer.toString(c.getCount()));

      String[][] matrix = new String[lista.size()][3];

      for (int i = 0; i < lista.size(); i++) {
          String[] aDado2 = new String[3];
          aDado2 = lista.get(i);
          matrix[i][0] = aDado2[0];
          matrix[i][1] = aDado2[1];
          matrix[i][2] = aDado2[2];

      }

      Arrays.sort(matrix, new Comparator<String[]>() {
          @Override
          public int compare(String[] o1, String[] o2) {
              final String descricao1 = o1[0];
              final String descricao2 = o2[0];
              return descricao1.compareTo(descricao2);
          }

      });

      try {

          TableLayout t1 = (TableLayout) findViewById(R.id.main_table);
          t1.removeAllViews();
          TableLayout tl = (TableLayout) findViewById(R.id.main_table);

          View divider;

          divider = new View(this);
          divider.setLayoutParams(new TableLayout.LayoutParams(1, 1));
          divider.setBackgroundColor(Color.BLACK);

          TableRow tr_head = new TableRow(this);
          tr_head.setId(10);
          tr_head.setBackgroundColor(Color.GRAY);

          tr_head.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                  LayoutParams.MATCH_PARENT));

          TextView check = new TextView(this);
          check.setId(20);
          check.setText("CHECK");
          check.setTextColor(Color.BLACK);
          check.setTextSize(20);
          check.setPadding(5, 5, 5, 5);
          tr_head.addView(check);

          TextView label_codigo = new TextView(this);
          label_codigo.setId(20);
          label_codigo.setText("CÓDIGO");
          label_codigo.setTextColor(Color.BLACK);
          label_codigo.setTextSize(20);
          label_codigo.setPadding(5, 5, 5, 5);
          tr_head.addView(label_codigo);

          TextView label_cod = new TextView(this);
          label_cod.setId(21);
          label_cod.setText("DESCRIÇÃO");
          label_cod.setTextColor(Color.BLACK);
          label_cod.setTextSize(20);
          label_cod.setPadding(5, 5, 5, 5);
          tr_head.addView(label_cod);

          TextView label_cozinha = new TextView(this);
          label_cozinha.setId(22);
          label_cozinha.setText("COZINHA");
          label_cozinha.setTextColor(Color.BLACK);
          label_cozinha.setTextSize(20);
          label_cozinha.setPadding(5, 5, 5, 5);
          tr_head.addView(label_cozinha);

          TextView label_galpao = new TextView(this);
          label_galpao.setId(23);
          label_galpao.setText("1º GALPÃO");
          label_galpao.setTextColor(Color.BLACK);
          label_galpao.setTextSize(20);
          label_galpao.setPadding(5, 5, 5, 5);
          tr_head.addView(label_galpao);

          TextView label_total = new TextView(this);
          label_total.setId(24);
          label_total.setText("TOTAL");
          label_total.setTextColor(Color.BLACK);
          label_total.setTextSize(20);
          label_total.setWidth(250);
          label_total.setPadding(5, 5, 5, 5);
          tr_head.addView(label_total);

          TextView label_newage = new TextView(this);
          label_newage.setId(25);
          label_newage.setText("NEWAGE");
          // label_newage.setWidth(150);
          label_newage.setTextColor(Color.BLACK);
          label_newage.setTextSize(20);
          label_newage.setPadding(5, 5, 5, 5);
          tr_head.addView(label_newage);

          TextView label_reserva = new TextView(this);
          label_reserva.setId(26);
          label_reserva.setText("RESERVA");
          // label_newage.setWidth(150);
          label_reserva.setTextColor(Color.BLACK);
          label_reserva.setTextSize(20);
          label_reserva.setPadding(5, 5, 5, 5);
          tr_head.addView(label_reserva);

          tl.addView(tr_head, new TableLayout.LayoutParams(
                  LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

          tl.addView(divider);

          for (int count = 0; count < matrix.length; count++) {
              final String descricao = matrix[count][0];
              final String cozinha = matrix[count][1];
              final String codigo = matrix[count][2];
              TableRow tr = new TableRow(this);

              String galpao = "";
              Cursor c2 = b
                      .getConnection()
                      .query("CONFERENCIA_GALPAO1",
                              new String[] { "SUBSTR(CODIGO,1,14)",
                                      "SUM(CAPACIDADE)" },
                              "SUBSTR(CODIGO,1,14)=? AND VERSAO=? AND LEVANTAMENTO=?",
                              new String[] { codigo, versao, "F" },
                              "SUBSTR(CODIGO,1,14)", null, null);
              if (c2.moveToFirst()) {
                  galpao = c2.getString(1);

                  do {
                  } while (c2.moveToNext());
              }

              String peso = "";
              String reserva = "";

              if (galpao.equalsIgnoreCase("") || galpao == null) {
                  galpao = "0.00";
              }

              String total = Float.toString(Float.parseFloat(cozinha)
                      + Float.parseFloat(galpao));

              Cursor c3 = b.getConnection().query("CONFERENCIA_NEWAGE",
                      new String[] { "PESO", "RESERVA" },
                      "CODIGO=? AND VERSAO=?",
                      new String[] { codigo, versao }, null, null, null);
              if (c3.moveToFirst()) {
                  peso = c3.getString(0);
                  reserva = c3.getString(1);
                  // Log.e("Total: ", total);
                  do {
                  } while (c3.moveToNext());
              }

              if (peso == null || peso.equalsIgnoreCase("")) {
                  peso = "0.0";
              }

              if (reserva == null || reserva.equalsIgnoreCase("")) {
                  reserva = "0.00";
              }

              Float numero = (float) (Float.parseFloat(cozinha) + Float
                      .parseFloat(galpao));

              Float menor = (float) (numero * 0.95);
              Float maior = (float) (numero * 1.05);

              // Log.e("Resultados", Integer.toString(c2.getCount()));

              divider = new View(this);
              divider.setLayoutParams(new TableLayout.LayoutParams(1, 1));
              divider.setBackgroundColor(Color.BLACK);

              TextView lCodigo = new TextView(this);
              TextView lDescricao = new TextView(this);
              TextView lCozinha = new TextView(this);
              TextView lGalpao = new TextView(this);
              TextView lTotal = new TextView(this);
              TextView lNew = new TextView(this);
              TextView lReserva = new TextView(this);
              CheckBox chk = new CheckBox(this);

              chk.setBackgroundColor(Color.WHITE);
              lCodigo.setBackgroundColor(Color.LTGRAY);
              lDescricao.setBackgroundColor(Color.WHITE);
              lCozinha.setBackgroundColor(Color.LTGRAY);
              lGalpao.setBackgroundColor(Color.WHITE);
              lTotal.setBackgroundColor(Color.LTGRAY);
              lNew.setBackgroundColor(Color.WHITE);
              lReserva.setBackgroundColor(Color.LTGRAY);

              tr.setId(100 + count);
              tr.setLayoutParams(new TableLayout.LayoutParams(
                      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
              tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                      LayoutParams.MATCH_PARENT));

              chk.setId(20 + Integer.parseInt(codigo.substring(6, 14)
                      .replace(".", "")) + 1000);
              chk.setPadding(5, 5, 5, 5);
              tr.addView(chk);

              lCodigo.setId(1200 + count);
              lCodigo.setTypeface(null, Typeface.BOLD);
              lCodigo.setText(codigo);
              lCodigo.setPadding(5, 5, 5, 5);
              lCodigo.setTextColor(Color.BLACK);
              lCodigo.setTextSize(20);
              tr.addView(lCodigo);

              lDescricao.setId(200 + count);
              lDescricao.setTypeface(null, Typeface.BOLD);
              lDescricao.setText(descricao);
              lDescricao.setPadding(5, 5, 5, 5);
              lDescricao.setTextColor(Color.BLACK);
              lDescricao.setTextSize(20);
              lDescricao.setClickable(true);
              lDescricao.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      Intent i = new Intent(getApplicationContext(),
                              ProdutoVersaoDetalhado.class);
                      i.putExtra("Codigo", codigo);
                      i.putExtra("Versao", versao);
                      startActivity(i);
                  }
              });
              tr.addView(lDescricao);

              lCozinha.setId(300 + count);
              lCozinha.setTypeface(null, Typeface.BOLD);
              lCozinha.setText(cozinha);
              lCozinha.setWidth(120);
              lCozinha.setPadding(5, 5, 5, 5);
              lCozinha.setTextColor(Color.BLACK);
              lCozinha.setTextSize(20);
              tr.addView(lCozinha);

              lGalpao.setId(400 + count);
              lGalpao.setText(galpao);
              lGalpao.setTypeface(null, Typeface.BOLD);
              lGalpao.setWidth(120);
              lGalpao.setPadding(5, 5, 5, 5);
              lGalpao.setTextColor(Color.BLACK);
              lGalpao.setTextSize(20);
              tr.addView(lGalpao);

              lTotal.setId(20 + Integer.parseInt(codigo.substring(6, 14)
                      .replace(".", "")) + 500);
              lTotal.setText(total);
              lTotal.setPadding(5, 5, 5, 5);
              lTotal.setWidth(120);
              lTotal.setTypeface(null, Typeface.BOLD);
              lTotal.setTextColor(Color.BLACK);
              lTotal.setTextSize(20);
              tr.addView(lTotal);

              lNew.setId(20 + Integer.parseInt(codigo.substring(6, 14)
                      .replace(".", "")) + 600);
              lNew.setText(peso);
              // lNew.setWidth(120);
              lNew.setPadding(5, 5, 5, 5);
              lNew.setTypeface(null, Typeface.BOLD);
              lNew.setTextColor(Color.BLACK);
              lNew.setTextSize(20);
              tr.addView(lNew);

              lReserva.setId(20 + Integer.parseInt(codigo.substring(6, 14)
                      .replace(".", "")) + 700);
              lReserva.setText(reserva);
              lReserva.setTypeface(null, Typeface.BOLD);
              lReserva.setPadding(5, 5, 5, 5);
              lReserva.setTextColor(Color.BLACK);
              lReserva.setTextSize(20);
              tr.addView(lReserva);

              // Log.e("Resultado: ", peso + " - " + Float.toString(menor)
              // + " - " + Float.toString(maior));

              if (Float.parseFloat(peso) >= menor
                      && Float.parseFloat(peso) <= maior) {
                  chk.setChecked(true);
                  chk.setBackgroundColor(Color.GREEN);
                  lCodigo.setBackgroundColor(Color.GREEN);
                  lDescricao.setBackgroundColor(Color.GREEN);
                  lCozinha.setBackgroundColor(Color.GREEN);
                  lGalpao.setBackgroundColor(Color.GREEN);
                  lTotal.setBackgroundColor(Color.GREEN);
                  lNew.setBackgroundColor(Color.GREEN);
                  lReserva.setBackgroundColor(Color.GREEN);
              } else {
                  chk.setChecked(false);
                  chk.setBackgroundColor(Color.RED);
                  lCodigo.setBackgroundColor(Color.RED);
                  lDescricao.setBackgroundColor(Color.RED);
                  lCozinha.setBackgroundColor(Color.RED);
                  lGalpao.setBackgroundColor(Color.RED);
                  lTotal.setBackgroundColor(Color.RED);
                  lNew.setBackgroundColor(Color.RED);
                  lReserva.setBackgroundColor(Color.RED);
              }

              if (numero == 0.0) {
                  chk.setChecked(false);
                  chk.setBackgroundColor(Color.YELLOW);
                  lCodigo.setBackgroundColor(Color.YELLOW);
                  lDescricao.setBackgroundColor(Color.YELLOW);
                  lCozinha.setBackgroundColor(Color.YELLOW);
                  lGalpao.setBackgroundColor(Color.YELLOW);
                  lTotal.setBackgroundColor(Color.YELLOW);
                  lNew.setBackgroundColor(Color.YELLOW);
                  lReserva.setBackgroundColor(Color.YELLOW);
              }

              divider = new View(this);
              divider.setLayoutParams(new TableLayout.LayoutParams(1, 1));

              divider.setBackgroundColor(Color.BLACK);

              tl.addView(tr, new TableLayout.LayoutParams(50, 1));

              tl.addView(divider);

          }
      } catch (NullPointerException e) {
          Toast.makeText(getBaseContext(), "Null Pointer Exception",
                  Toast.LENGTH_LONG).show();
      }

      return matrix;
  }

在这里我称呼他们:

  

@SuppressWarnings({&#34; unused&#34;,&#34; rawtypes&#34;,&#34; unchecked&#34;})private void   enviaDadosNewage(查看v){// TODO自动生成的方法存根

  String response = null;         String xml = null;      TextView lTotal;
  TextView lNew;      TextView lReserva;

  Banco b = new Banco(contextoApp, "Produtos.db", null, 1);

  Cursor c = b.getConnection().query(
          "CONFERENCIA_COZINHA",
          new String[] { "CODIGO", "DESCRICAO", "CAPACIDADE", "ESTANTE",
                  "DENSIDADE", "FISICO", "VERSAO" }, "VERSAO=?",
          new String[] { versao }, null, null, "DESCRICAO");      ArrayList<String[]> lista = new ArrayList<String[]>();      if
     

(c.moveToFirst()){

      do {
          String[] aDado = new String[7];
          aDado[0] = c.getString(0);
          aDado[1] = c.getString(1);
          aDado[2] = c.getString(2);
          aDado[3] = c.getString(3);
          aDado[4] = c.getString(4);
          aDado[5] = c.getString(5);
          aDado[6] = c.getString(6);

          lista.add(aDado);

      } while (c.moveToNext());       }

  Cursor corantes = b.getConnection().query("CONFERENCIA_CORANTES",
          new String[] { "CODIGO", "DESCRICAO", "FISICO", "VERSAO" },
          "VERSAO=?", new String[] { versao }, null, null, "DESCRICAO");      if (corantes.moveToFirst()) {

      do {
          String[] aDado = new String[7];
          aDado[0] = corantes.getString(0);
          aDado[1] = corantes.getString(1);
          aDado[2] = corantes.getString(2);
          aDado[3] = corantes.getString(3);
          aDado[4] = "";
          aDado[5] = "";
          aDado[6] = "";

          lista.add(aDado);

      } while (corantes.moveToNext());        }

  String[][] matrix = new String[lista.size()][7];

  String inventario = pegaInventario();

  for (int i = 0; i < lista.size(); i++) {            String[] aDado2 = new
     

的字符串[7]; aDado2 = lista.get(i); matrix [i] [0] = aDado2 [0];             matrix [i] [1] = aDado2 [1]; matrix [i] [2] = aDado2 [2];             matrix [i] [3] = aDado2 [3]; matrix [i] [4] = aDado2 [4];             matrix [i] [5] = aDado2 [5]; matrix [i] [6] = aDado2 [6];

  }

  ArrayList<String[]> listanova = new ArrayList<String[]>();      for
     

(int count = 0; count&lt; lista.size(); count ++){CheckBox复选框   =(CheckBox)findViewById(20 + Integer                     .parseInt(matrix [count] [0] .substring(6,14)                             .replace(&#34;。&#34;,&#34;&#34;))+ 1000); if(checkbox.isChecked()){                 listanova.add(矩阵[COUNT]); }}

  String[][] matriznova = new String[listanova.size()][7];

  for (int i = 0; i < listanova.size(); i++) {            String[] arraydados
     

= new String [7]; arraydados = listanova.get(i); matriznova [i] [0] = arraydados [0]; matriznova [i] [1] = arraydados [1]; matriznova [i] [2] = arraydados [2]; matriznova [i] [3] =   arraydados [3]; matriznova [i] [4] = arraydados [4];             matriznova [i] [5] = arraydados [5]; matriznova [i] [6] =   arraydados [6]; }

  ArrayList a = new ArrayList();

  for (int count = 0; count < matriznova.length; count++) {

      lTotal = (TextView) findViewById(20 + Integer
              .parseInt(matriznova[count][0].substring(6, 14).replace(
                      ".", "")) + 500);

      lNew = (TextView) findViewById(20 + Integer
              .parseInt(matriznova[count][0].substring(6, 14).replace(
                      ".", "")) + 600);

      lReserva = (TextView) findViewById(20 + Integer
              .parseInt(matriznova[count][0].substring(6, 14).replace(
                      ".", "")) + 700);

      if (lTotal.getText().toString().equalsIgnoreCase("")
              || lReserva.getText().toString().equalsIgnoreCase("")) {

      } else {

          Float resultado = Float.parseFloat(lTotal.getText().toString())
                  + Float.parseFloat(lReserva.getText().toString());

          String usuario = "";

          Cursor c1 = b.getConnection().query("CONFIGURACOES",
                  new String[] { "USUARIO" }, null, null, null, null,
                  null);

          if (c1.moveToFirst()) {
              do {
                  usuario = c1.getString(0);
              } while (c1.moveToNext());
          }

          if (Float.toString(resultado).equalsIgnoreCase("0")
                  || Float.toString(resultado).equalsIgnoreCase("0.0")) {
              String[] dados = new String[1];
              dados[0] = matriznova[count][0] + "','"
                      + Float.toString(resultado) + "','" + inventario
                      + "','" + usuario.toUpperCase();

          } else {

              String[] dados = new String[1];
              dados[0] = matriznova[count][0] + "','"
                      + Float.toString(resultado) + "','" + inventario
                      + "','" + usuario.toUpperCase();

              a.add(dados[0]);
          }           }       }       String parametro = "{";

  for (int i = 0; i < a.size(); i++) {

      if ((a.size() - i) != 1) {
          parametro += "{'" + a.get(i) + "'},";

      } else {

          parametro += "{'" + a.get(i) + "'}";            }

  }

  parametro += "}";

  // Log.d("Parametro:     ", parametro);

  String usuario = "";        String senha = "";      String base = "";
  String URL = "";        //
     

/////////////////////////////////////////////// /////////////字符串   NAMESPACE =&#34; http://tempuri.org/&#34 ;;字符串METHOD_NAME =   &#34; executarComando&#34 ;; String SOAP_ACTION =   &#34; http://tempuri.org/executarComando&#34 ;;

  Cursor select = b.getConnection()
          .query("CONFIGURACOES",
                  new String[] { "CODIGO", "USUARIO", "SENHA",
                          "ENDERECO", "BASE" }, "CODIGO = ?",
                  new String[] { Integer.toString(1) }, null, null, null);

  if (select.moveToFirst()) {             do {
          usuario = select.getString(1);
          senha = select.getString(2);
          URL = select.getString(3);
          base = select.getString(4);             } while (select.moveToNext());      }

  // Log.i("Usuario: ", usuario);         // Log.i("Senha: ", senha);         //
     

Log.i(&#34;网址:&#34;,网址); // Log.i(&#34; Base:&#34;,base);

  HttpClient httpClient = new DefaultHttpClient();        HttpPost httpPost
     

= new HttpPost(URL);

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
          SoapEnvelope.VER11);        envelope.encodingStyle = SoapSerializationEnvelope.ENC;         envelope.implicitTypes = true;

  String bodyOut = "<?xml version=\"1.0\"
     

编码= \&#34; UTF-8 \&#34;&GT; HTTP://www.w3.org/2001/XMLSchema-instance \&#34;   的xmlns:XSD = \&#34; HTTP://www.w3.org/2001/XMLSchema \&#34;   的xmlns:SOAP = \&#34; HTTP://schemas.xmlsoap.org/soap/envelope/ \&#34;&GT;&#34 ;; bodyOut   =&#34; http://www.w3.org/2003/05/soap-envelope \&#34; &#34;                 +&#34;的xmlns:TEM = \&#34; HTTP://tempuri.org/ \&#34; &GT; &#34; +&#34; &#34;                 +&#34;&#34; +&#34; &#34;                 +&#34; FLO_AT_INVENTARIO:执行(&#34;                 + parametro.trim()+&#34;)&#34;                 +&#34; &#34; +基地+&#34; &#34;                 +&#34; &#34; + usuario +&#34; &#34;                 +&#34; &#34; + senha +&#34; &#34;                 +&#34; &#34; +&#34; &#34;                 +&#34;&#34;;

  xml = bodyOut;      // Log.d("XML: ", xml);

  StringEntity se;        try {           se = new StringEntity(xml, HTTP.UTF_8);
      se.setContentType("text/xml");          httpPost.addHeader(SOAP_ACTION,
     

URL); httpPost.setEntity(SE);

      try {
          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity resEntity = httpResponse.getEntity();
          response = EntityUtils.toString(resEntity);             } catch (NetworkOnMainThreadException e) {
          Toast msg = Toast.makeText(getApplicationContext(),
                  "Erro do HTTP", Toast.LENGTH_LONG);
          msg.show();
          e.printStackTrace();
          return;             } catch (HttpHostConnectException e) {
          // TODO Auto-generated catch block
          Toast msg = Toast.makeText(getApplicationContext(),
                  "Não está conectado a uma rede válida",
                  Toast.LENGTH_LONG);
          msg.show();

          return;             }

      // Log.d("Resposta: ", response);

  } catch (UnsupportedEncodingException e) {          // TODO Auto-generated
     

catch block e.printStackTrace(); } catch(ClientProtocolException   e){// TODO自动生成的catch块e.printStackTrace(); }   catch(IOException e){// TODO自动生成的catch块             e.printStackTrace(); }

  if (response == null) {             Toast.makeText(getApplicationContext(),
     

&#34; response = null&#34;,                     Toast.LENGTH_LONG).show();返回; } else if(response.contains(&#34; Cache&#34;)){

      Toast.makeText(getApplicationContext(), "Erro de cache",
              Toast.LENGTH_LONG).show();          // Log.i("Diogo",           // "Response = null = Classe LeituraCozinha.java linha 397");           return;         }

  int ini = response.lastIndexOf("<String xmlns=\"\">") + 17;         int
     

fin = response.lastIndexOf(&#34;&#34;);

  String CONTEUDO = response.substring(ini, fin);

  if (CONTEUDO.equalsIgnoreCase("{}")) {          return;         } else if
     

(CONTEUDO.equalsIgnoreCase(&#34; .F。&#34;)){confirmado =&#34; S&#34 ;; //   返回; }

     

}

看看我调用3个textviews并且没有问题,只需复选框

0 个答案:

没有答案