In main activity i send the String[] name like this:
private void sendNames() {
Bundle b=new Bundle();
b.putStringArray("key", names);
Intent i=new Intent(this, ListFriendsFragment.class);
i.putExtras(b);
}
when i send names it is not empty 100%, and put this code in a method, and called it after the i get the names.
In activity i want to receive the string[] i get it like this:
names = this.getIntent().getExtras().getStringArray("key");
In both, main activity and the one i want to receive the string, names
is declared as follows:
private String[] names;
When i start the activity which should get the names
the application crashes:
Caused by: java.lang.NullPointerException
at com.utm.course.friendslist.ListFriendsFragment.PrintNames(ListFriendsFragment.java:26)
at com.utm.course.friendslist.ListFriendsFragment.onCreate(ListFriendsFragment.java:20)
What am i doing wrong?
Update
these are parts where i use Intent
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (currentSession != null) {
currentSession.onActivityResult(this, requestCode, resultCode, data);
}
}
...
private void sendNames() {
Log.d("sendNames", "started");
Bundle b=new Bundle();
b.putStringArray(key, names);
Intent i=new Intent(this, ListFriendsFragment.class);
i.putExtras(b);
}
...
private void listFriends() {
Log.d("Activity", "List Friends Activity Starting");
Intent i=new Intent(MainActivity.this,ListFriendsFragment.class);
startActivity(i);
finish();
}