,我要開始我與構造 我想通過對象的數組活動不使用偏好的唯一解決的一個問題是使用構造活動與構造
public class ApresConnextionActivity extends Activity {
public Bts[] listeBts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.apresconnect);
final Button btsButton = (Button) findViewById(R.id.btbts);
//boutonbts
btsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.w("myApp",""+listeBts.length);
BtsBoutonActivity btba = new BtsBoutonActivity(listeBts);
Intent i = new Intent(getApplicationContext(), btba.getClass());
startActivity(i);
}
});
new JSONParseBts().execute();
}
public class JSONParseBts extends AsyncTask<String, String, JSONObject> { ... }
}
public class BtsBoutonActivity extends Activity {
Bts[] listeBts;
cellule[] listecellule;
int i,xx=0;
public BtsBoutonActivity(Bts[] listeBts2) {
this.listeBts=listeBts2;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.btsbouton);
//Log.w("myApp",""+listeBts.length);
final Button[] b = new Button[listeBts.length];
LinearLayout ll3 = (LinearLayout)findViewById(R.id.linearLayout2); // Btn
for(i = 0; i < listeBts.length; i++){
//Log.w("myApp",listeBts[i].toString());
b[i] = new Button(BtsBoutonActivity.this);
b[i].setText(listeBts[i].getNombts());
xx =listeBts[i].getIdbts();
Log.w("myApp",""+xx);
b[i].setId(xx);
ll3.addView(b[i]);
final Button btbts = (Button) findViewById(xx);
btbts.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast saved_message=Toast.makeText(BtsBoutonActivity.this,btbts.getText()+" "+btbts.getId(),1);
saved_message.show();
}});
}
}
}
05-09 20:14:31.121: E/AndroidRuntime(596): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pfe.essat.com/pfe.essat.com.BtsBoutonActivity}: java.lang.InstantiationException: can't instantiate class pfe.essat.com.BtsBoutonActivity; no empty constructor
這是對一個問題聲明在文件清單也許! 預先感謝您
thx很多 我試過但你怎麼傳遞一個特定的列表(不是字符串,int ..等) 我喜歡這樣做** i.putExtra(「tabbts」,listeBts); ** 我調用** Bundle b = getIntent()。getExtras(); ** ** listeBts =(Bts [])b.get(「lisbts」); **錯誤是'無法編組值Bts ' – hchems
您需要該類來實現parcelable/serializable。請參閱我提供的鏈接。或者,您可以使用公共靜態數組創建自定義類,然後在啓動活動之前,將其設置爲數組並在另一端讀取它。你也可以通過你的應用程序類傳遞數據,sql也是 –
它就是我所做的(可序列化)我的數組已經建立起價格從sql查詢開始我想盡量減少與數據庫的通信,這就是爲什麼現在當我想使用數組的時候 erreur是 ** java.lang.RuntimeException:無法啓動活動ComponentInfo {pfe.essat.com/pfe.essat.com.BtsBoutonActivity}:java.lang.NullPointerException ** 該數組爲空:/ – hchems