主要活动
public void onClick(View v) {
String[] arraynomb = arreglonombreprod.toArray(new String[0]);
String[] arrayprecios = precioproductoarreglo.toArray(new String[0]);
String[] arraycant = arreglocantidadprod.toArray(new String[0]);
Bundle extras = new Bundle();
Intent intent = new Intent(getApplicationContext(),claseinventario.class);
extras.putStringArray("productosx", arraynomb);
extras.putStringArray("preciosx", arrayprecios);
extras.putStringArray("cantidadesx", arraycant);
intent.putExtras(extras);
startActivity(intent);
}
});
另一个班级
公共类 claseinventario 扩展 Activity {
ListViewAdapter adapter;
Bundle extras = getIntent().getExtras();
String[] prod = extras.getStringArray("productosx");
String[] cant = extras.getStringArray("preciosx");
String[] pre = extras.getStringArray("cantidadesx");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lista);
final ListView lista = (ListView) findViewById(R.id.viewlista);
adapter = new ListViewAdapter(this, prod, pre, cant);
lista.setAdapter(adapter);
}
日志猫:
02-22 14:52:58.975: E/AndroidRuntime(6623): FATAL EXCEPTION: main
02-22 14:52:58.975: E/AndroidRuntime(6623): java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.example.manuel.supercontrol/com.example.manuel.supercontrol.claseinventario}: java.lang .NullPointerException 02-22 14:52:58.975:E/AndroidRuntime(6623):引起:java.lang.NullPointerException
02-22 14:52:58.975: E/AndroidRuntime(6623): at com.example.manuel.supercontrol.claseinventario.(claseinventario.java:15)
第 15 行是 - 捆绑额外内容 = getIntent().getExtras();