2015-04-04 84 views
3

我堅持這個錯誤。[Android]對象不能轉換爲java.lang.String Asynctask

java.lang.ClassCastException:java.lang.Object中[]不能被轉換爲java.lang.String []

這是全碼。

` 保護無效onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

edTenDangNhap =(EditText) findViewById(R.id.edTenDangNhap); 
    edMatKhau =(EditText) findViewById(R.id.edMatKhau); 
    btnDangKi =(Button) findViewById(R.id.btnDangKi); 
    btnDangNhap =(Button) findViewById(R.id.btnDangNhap); 

    btnDangNhap.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String tentk = edTenDangNhap.getText().toString(); 
      String matkhau = edMatKhau.getText().toString(); 

      // ==== I execute AsyncTask there 
      AsyncTask dangnhap = new AsyncDangNhap(); 
      dangnhap.execute(tentk,matkhau); // IDE announce there : JDK 5.0 only. Unchecked to call execute Params ... 
     } 
    }); 
} 
public class AsyncDangNhap extends AsyncTask<String[], Void, Integer>{//error there 
    @Override 
    protected Integer doInBackground(String[]... params) { 
     WebService sv = new WebService(); 
     int kiemtra = sv.KiemTraDangNhap(params[0],params[1]); 
     return kiemtra; 
    } 
    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     Toast.makeText(getApplicationContext(),"Dang xu li ... !",Toast.LENGTH_LONG).show(); 
    } 
    @Override 
    protected void onPostExecute(Integer result) { 
     super.onPostExecute(result); 
     if(result >0){ 
      //Dang nhap thanh cong 
      Toast.makeText(getApplicationContext(),"Dang nhap thanh cong !",Toast.LENGTH_LONG).show(); 
     }else{ 
      Toast.makeText(getApplicationContext(),"Dang nhap that bai !",Toast.LENGTH_LONG).show(); 
     } 
    } 
}` 

回答

1

變化String[]StringAsyncTaskdoInBackground方法,因爲目前這個字符串在dangnhap.execute方法,而不是字符串Array.like:

public class AsyncDangNhap extends AsyncTask<String, Void, Integer>{ 
    @Override 
    protected Integer doInBackground(String... params) { 
     ..... 
    } 

    .... 
} 
+0

韓國社交協會,但我嘗試使用字符串和字符串[],但它仍然是不行。任何機會'關於jdk的問題,因爲有人仍在使用這個代碼!? – 2015-04-04 01:29:07

相關問題