I'm trying to pass information from one Activity
to another through the position in the list, but it's giving this nullpointer
error.
Where do I get the information - Main Activity
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(PrincipalActivity.this, ListaPermissoesActivity.class);
Bundle bundle= new Bundle();
String nome = carrega_container.getNomeApp(position);
String msg = carrega_container.getPermissoes(position);
bundle.putString("nome", nome);
bundle.putString("msg", msg);
intent.putExtras(bundle);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Abrindo informaçoes...", Toast.LENGTH_SHORT).show();
}
Activity that should receive information (error should be here)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_permissoes);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String nome = bundle.getString("nome");
TextView appNome = (TextView) view.findViewById(R.id.nome_app);
appNome.setText(nome);
setContentView(appNome);
String msg = bundle.getString("msg");
TextView appPermissao = (TextView) view.findViewById(R.id.txt_lista);
appPermissao.setText(msg);
setContentView(appPermissao);
}
The name in the xmls are correct.
Error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.br.listadeaplicativos, PID: 5113
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.br.listadeaplicativos/com.android.br.listadeaplicativos.ListaPermissoesActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
at com.android.br.listadeaplicativos.ListaPermissoesActivity.onCreate(ListaPermissoesActivity.java:28)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)