Main activity
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);
}
});
the other class
public class claseinventario extends 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);
}
logcat:
02-22 14:52:58.975: E/AndroidRuntime(6623): FATAL EXCEPTION: main
02-22 14:52:58.975: E/AndroidRuntime(6623): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.manuel.supercontrol/com.example.manuel.supercontrol.claseinventario}: java.lang.NullPointerException 02-22 14:52:58.975: E/AndroidRuntime(6623): Caused by: java.lang.NullPointerException
02-22 14:52:58.975: E/AndroidRuntime(6623): at com.example.manuel.supercontrol.claseinventario.(claseinventario.java:15)
line 15# is - Bundle extras = getIntent().getExtras();
Try this instead:
And to retrieve them:
To make the code even cleaner, you should consider using standard Java class naming conventions (uppercase Class names, for example), and constant values for the
Extra
names, but the code above should work fine.