Can't get actvity to navigate to another activity












1















I've got 2 activities that stores/get data from firebase, different data but they are related to each other.



The first activity stores for example different food dishes in a listview, and when I click on one of the items I get to the second activity where I can store different things under the first item i chose in my first activity. So for example, if I click on "PIZZA" I get to a new activity where I can store "Italian Pizza". And this is working fine. But I want to have a middle activity that will appear after my first activity, and in this middle activity I want to have a button that gets me to my second activity.



So between the first and second activity it is no problem, works like a charm. But when I try to use this middle activity with a button, it doesn't work. I guess it has to have something to do with the middle activity, that it is not "connected" with the database for the other activities. But I don't know, need help :)



I get this error when trying to click on the add button:



java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)


First Activity:



public class Jobbliste extends AppCompatActivity {

DatabaseReference databaseJobber;

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView jobbliste
ListView listjobber;
ImageView leggtiljobb;

List<Jobber> listjobb;

{

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jobbliste);

databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber");
databaseVerktøy = FirebaseDatabase.getInstance().getReference("Verktøy");
databaseAnsatt = FirebaseDatabase.getInstance().getReference("Ansatte");


jobbliste = (TextView) findViewById(R.id.tvjobbliste);
listjobber = (ListView) findViewById(R.id.lvjobbliste);

listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {


Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);

intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());

startActivity(intent);

return false;


}
});


leggtiljobb = (ImageView) findViewById(R.id.tvleggtiljobb);

listjobb = new ArrayList<>();
søkjobb = new ArrayList<>();

leggtiljobb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(Jobbliste.this, Leggtiljobb.class);
startActivity(leggtil);

}
});


}

@Override
protected void onStart() {
super.onStart();

databaseJobber.orderByChild("jobbnavn").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

listjobb.clear();

for (DataSnapshot jobberSnapshot : dataSnapshot.getChildren()) {

final Jobber jobber = jobberSnapshot.getValue(Jobber.class);

listjobb.add(jobber);

final listJobber adapter = new listJobber(Jobbliste.this, listjobb);
listjobber.setAdapter(adapter);

adapter.notifyDataSetChanged();

}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
}


Second Activity:



public class Notater extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView tvjobbnavn;
EditText etnotater;
Button btnlagrenotat;
ListView lvnotater;
Button btntest;
TextView tvjobbnavn1;

DatabaseReference databaseNotater;
DatabaseReference databaseJobber;

List<Notat> notater;
List<Jobber> listjobb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notater);


tvjobbnavn = (TextView) findViewById(R.id.tvjobbnavn);
tvjobbnavn1 = (TextView) findViewById(R.id.tvjobbnavn1);

etnotater = (EditText) findViewById(R.id.etnotater);
btnlagrenotat = (Button) findViewById(R.id.btnlagrenotat);
lvnotater = (ListView) findViewById(R.id.lvnotater);
btntest = (Button) findViewById(R.id.btntest);
lvnotater.setItemsCanFocus(true);


Intent intent = getIntent();

notater = new ArrayList<>();
listjobb = new ArrayList<>();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

tvjobbnavn.setText(navn);


databaseNotater = FirebaseDatabase.getInstance().getReference("Notater").child(id);
databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber").child(id);


btnlagrenotat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lagrenotat();

}
});

}

@Override
protected void onStart() {
super.onStart();

databaseNotater.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notater.clear();

for (DataSnapshot notatsnapshot : dataSnapshot.getChildren()) {
Notat notat = notatsnapshot.getValue(Notat.class);
notater.add(notat);


}
listNotater notatlistadapter = new listNotater(Notater.this, notater);

lvnotater.setAdapter(notatlistadapter);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

private void lagrenotat() {
String notatavn = etnotater.getText().toString().trim();


if (!TextUtils.isEmpty(notatavn)) {
String id = databaseNotater.push().getKey();

Notat notat = new Notat(id, notatavn);
databaseNotater.child(id).setValue(notat);

} else {
Toast.makeText(this, "Skriv noe", Toast.LENGTH_SHORT).show();
}

}
}


My middle Activity:



public class MainActivity extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";

Button add;
TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

add = (Button) findViewById(R.id.add);
text = (TextView) findViewById(R.id.text);

Intent intent = getIntent();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

text.setText(navn);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);


}
});
}
}









share|improve this question

























  • So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

    – 0X0nosugar
    Nov 23 '18 at 18:52











  • Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

    – Alexander
    Nov 23 '18 at 19:06













  • You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

    – 0X0nosugar
    Nov 23 '18 at 19:10











  • The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

    – Alexander
    Nov 23 '18 at 19:14








  • 1





    Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

    – 0X0nosugar
    Nov 23 '18 at 19:17
















1















I've got 2 activities that stores/get data from firebase, different data but they are related to each other.



The first activity stores for example different food dishes in a listview, and when I click on one of the items I get to the second activity where I can store different things under the first item i chose in my first activity. So for example, if I click on "PIZZA" I get to a new activity where I can store "Italian Pizza". And this is working fine. But I want to have a middle activity that will appear after my first activity, and in this middle activity I want to have a button that gets me to my second activity.



So between the first and second activity it is no problem, works like a charm. But when I try to use this middle activity with a button, it doesn't work. I guess it has to have something to do with the middle activity, that it is not "connected" with the database for the other activities. But I don't know, need help :)



I get this error when trying to click on the add button:



java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)


First Activity:



public class Jobbliste extends AppCompatActivity {

DatabaseReference databaseJobber;

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView jobbliste
ListView listjobber;
ImageView leggtiljobb;

List<Jobber> listjobb;

{

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jobbliste);

databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber");
databaseVerktøy = FirebaseDatabase.getInstance().getReference("Verktøy");
databaseAnsatt = FirebaseDatabase.getInstance().getReference("Ansatte");


jobbliste = (TextView) findViewById(R.id.tvjobbliste);
listjobber = (ListView) findViewById(R.id.lvjobbliste);

listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {


Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);

intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());

startActivity(intent);

return false;


}
});


leggtiljobb = (ImageView) findViewById(R.id.tvleggtiljobb);

listjobb = new ArrayList<>();
søkjobb = new ArrayList<>();

leggtiljobb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(Jobbliste.this, Leggtiljobb.class);
startActivity(leggtil);

}
});


}

@Override
protected void onStart() {
super.onStart();

databaseJobber.orderByChild("jobbnavn").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

listjobb.clear();

for (DataSnapshot jobberSnapshot : dataSnapshot.getChildren()) {

final Jobber jobber = jobberSnapshot.getValue(Jobber.class);

listjobb.add(jobber);

final listJobber adapter = new listJobber(Jobbliste.this, listjobb);
listjobber.setAdapter(adapter);

adapter.notifyDataSetChanged();

}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
}


Second Activity:



public class Notater extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView tvjobbnavn;
EditText etnotater;
Button btnlagrenotat;
ListView lvnotater;
Button btntest;
TextView tvjobbnavn1;

DatabaseReference databaseNotater;
DatabaseReference databaseJobber;

List<Notat> notater;
List<Jobber> listjobb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notater);


tvjobbnavn = (TextView) findViewById(R.id.tvjobbnavn);
tvjobbnavn1 = (TextView) findViewById(R.id.tvjobbnavn1);

etnotater = (EditText) findViewById(R.id.etnotater);
btnlagrenotat = (Button) findViewById(R.id.btnlagrenotat);
lvnotater = (ListView) findViewById(R.id.lvnotater);
btntest = (Button) findViewById(R.id.btntest);
lvnotater.setItemsCanFocus(true);


Intent intent = getIntent();

notater = new ArrayList<>();
listjobb = new ArrayList<>();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

tvjobbnavn.setText(navn);


databaseNotater = FirebaseDatabase.getInstance().getReference("Notater").child(id);
databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber").child(id);


btnlagrenotat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lagrenotat();

}
});

}

@Override
protected void onStart() {
super.onStart();

databaseNotater.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notater.clear();

for (DataSnapshot notatsnapshot : dataSnapshot.getChildren()) {
Notat notat = notatsnapshot.getValue(Notat.class);
notater.add(notat);


}
listNotater notatlistadapter = new listNotater(Notater.this, notater);

lvnotater.setAdapter(notatlistadapter);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

private void lagrenotat() {
String notatavn = etnotater.getText().toString().trim();


if (!TextUtils.isEmpty(notatavn)) {
String id = databaseNotater.push().getKey();

Notat notat = new Notat(id, notatavn);
databaseNotater.child(id).setValue(notat);

} else {
Toast.makeText(this, "Skriv noe", Toast.LENGTH_SHORT).show();
}

}
}


My middle Activity:



public class MainActivity extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";

Button add;
TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

add = (Button) findViewById(R.id.add);
text = (TextView) findViewById(R.id.text);

Intent intent = getIntent();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

text.setText(navn);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);


}
});
}
}









share|improve this question

























  • So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

    – 0X0nosugar
    Nov 23 '18 at 18:52











  • Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

    – Alexander
    Nov 23 '18 at 19:06













  • You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

    – 0X0nosugar
    Nov 23 '18 at 19:10











  • The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

    – Alexander
    Nov 23 '18 at 19:14








  • 1





    Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

    – 0X0nosugar
    Nov 23 '18 at 19:17














1












1








1








I've got 2 activities that stores/get data from firebase, different data but they are related to each other.



The first activity stores for example different food dishes in a listview, and when I click on one of the items I get to the second activity where I can store different things under the first item i chose in my first activity. So for example, if I click on "PIZZA" I get to a new activity where I can store "Italian Pizza". And this is working fine. But I want to have a middle activity that will appear after my first activity, and in this middle activity I want to have a button that gets me to my second activity.



So between the first and second activity it is no problem, works like a charm. But when I try to use this middle activity with a button, it doesn't work. I guess it has to have something to do with the middle activity, that it is not "connected" with the database for the other activities. But I don't know, need help :)



I get this error when trying to click on the add button:



java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)


First Activity:



public class Jobbliste extends AppCompatActivity {

DatabaseReference databaseJobber;

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView jobbliste
ListView listjobber;
ImageView leggtiljobb;

List<Jobber> listjobb;

{

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jobbliste);

databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber");
databaseVerktøy = FirebaseDatabase.getInstance().getReference("Verktøy");
databaseAnsatt = FirebaseDatabase.getInstance().getReference("Ansatte");


jobbliste = (TextView) findViewById(R.id.tvjobbliste);
listjobber = (ListView) findViewById(R.id.lvjobbliste);

listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {


Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);

intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());

startActivity(intent);

return false;


}
});


leggtiljobb = (ImageView) findViewById(R.id.tvleggtiljobb);

listjobb = new ArrayList<>();
søkjobb = new ArrayList<>();

leggtiljobb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(Jobbliste.this, Leggtiljobb.class);
startActivity(leggtil);

}
});


}

@Override
protected void onStart() {
super.onStart();

databaseJobber.orderByChild("jobbnavn").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

listjobb.clear();

for (DataSnapshot jobberSnapshot : dataSnapshot.getChildren()) {

final Jobber jobber = jobberSnapshot.getValue(Jobber.class);

listjobb.add(jobber);

final listJobber adapter = new listJobber(Jobbliste.this, listjobb);
listjobber.setAdapter(adapter);

adapter.notifyDataSetChanged();

}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
}


Second Activity:



public class Notater extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView tvjobbnavn;
EditText etnotater;
Button btnlagrenotat;
ListView lvnotater;
Button btntest;
TextView tvjobbnavn1;

DatabaseReference databaseNotater;
DatabaseReference databaseJobber;

List<Notat> notater;
List<Jobber> listjobb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notater);


tvjobbnavn = (TextView) findViewById(R.id.tvjobbnavn);
tvjobbnavn1 = (TextView) findViewById(R.id.tvjobbnavn1);

etnotater = (EditText) findViewById(R.id.etnotater);
btnlagrenotat = (Button) findViewById(R.id.btnlagrenotat);
lvnotater = (ListView) findViewById(R.id.lvnotater);
btntest = (Button) findViewById(R.id.btntest);
lvnotater.setItemsCanFocus(true);


Intent intent = getIntent();

notater = new ArrayList<>();
listjobb = new ArrayList<>();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

tvjobbnavn.setText(navn);


databaseNotater = FirebaseDatabase.getInstance().getReference("Notater").child(id);
databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber").child(id);


btnlagrenotat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lagrenotat();

}
});

}

@Override
protected void onStart() {
super.onStart();

databaseNotater.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notater.clear();

for (DataSnapshot notatsnapshot : dataSnapshot.getChildren()) {
Notat notat = notatsnapshot.getValue(Notat.class);
notater.add(notat);


}
listNotater notatlistadapter = new listNotater(Notater.this, notater);

lvnotater.setAdapter(notatlistadapter);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

private void lagrenotat() {
String notatavn = etnotater.getText().toString().trim();


if (!TextUtils.isEmpty(notatavn)) {
String id = databaseNotater.push().getKey();

Notat notat = new Notat(id, notatavn);
databaseNotater.child(id).setValue(notat);

} else {
Toast.makeText(this, "Skriv noe", Toast.LENGTH_SHORT).show();
}

}
}


My middle Activity:



public class MainActivity extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";

Button add;
TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

add = (Button) findViewById(R.id.add);
text = (TextView) findViewById(R.id.text);

Intent intent = getIntent();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

text.setText(navn);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);


}
});
}
}









share|improve this question
















I've got 2 activities that stores/get data from firebase, different data but they are related to each other.



The first activity stores for example different food dishes in a listview, and when I click on one of the items I get to the second activity where I can store different things under the first item i chose in my first activity. So for example, if I click on "PIZZA" I get to a new activity where I can store "Italian Pizza". And this is working fine. But I want to have a middle activity that will appear after my first activity, and in this middle activity I want to have a button that gets me to my second activity.



So between the first and second activity it is no problem, works like a charm. But when I try to use this middle activity with a button, it doesn't work. I guess it has to have something to do with the middle activity, that it is not "connected" with the database for the other activities. But I don't know, need help :)



I get this error when trying to click on the add button:



java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)


First Activity:



public class Jobbliste extends AppCompatActivity {

DatabaseReference databaseJobber;

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView jobbliste
ListView listjobber;
ImageView leggtiljobb;

List<Jobber> listjobb;

{

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jobbliste);

databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber");
databaseVerktøy = FirebaseDatabase.getInstance().getReference("Verktøy");
databaseAnsatt = FirebaseDatabase.getInstance().getReference("Ansatte");


jobbliste = (TextView) findViewById(R.id.tvjobbliste);
listjobber = (ListView) findViewById(R.id.lvjobbliste);

listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {


Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);

intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());

startActivity(intent);

return false;


}
});


leggtiljobb = (ImageView) findViewById(R.id.tvleggtiljobb);

listjobb = new ArrayList<>();
søkjobb = new ArrayList<>();

leggtiljobb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(Jobbliste.this, Leggtiljobb.class);
startActivity(leggtil);

}
});


}

@Override
protected void onStart() {
super.onStart();

databaseJobber.orderByChild("jobbnavn").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

listjobb.clear();

for (DataSnapshot jobberSnapshot : dataSnapshot.getChildren()) {

final Jobber jobber = jobberSnapshot.getValue(Jobber.class);

listjobb.add(jobber);

final listJobber adapter = new listJobber(Jobbliste.this, listjobb);
listjobber.setAdapter(adapter);

adapter.notifyDataSetChanged();

}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}
}


Second Activity:



public class Notater extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";


TextView tvjobbnavn;
EditText etnotater;
Button btnlagrenotat;
ListView lvnotater;
Button btntest;
TextView tvjobbnavn1;

DatabaseReference databaseNotater;
DatabaseReference databaseJobber;

List<Notat> notater;
List<Jobber> listjobb;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notater);


tvjobbnavn = (TextView) findViewById(R.id.tvjobbnavn);
tvjobbnavn1 = (TextView) findViewById(R.id.tvjobbnavn1);

etnotater = (EditText) findViewById(R.id.etnotater);
btnlagrenotat = (Button) findViewById(R.id.btnlagrenotat);
lvnotater = (ListView) findViewById(R.id.lvnotater);
btntest = (Button) findViewById(R.id.btntest);
lvnotater.setItemsCanFocus(true);


Intent intent = getIntent();

notater = new ArrayList<>();
listjobb = new ArrayList<>();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

tvjobbnavn.setText(navn);


databaseNotater = FirebaseDatabase.getInstance().getReference("Notater").child(id);
databaseJobber = FirebaseDatabase.getInstance().getReference("Jobber").child(id);


btnlagrenotat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lagrenotat();

}
});

}

@Override
protected void onStart() {
super.onStart();

databaseNotater.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notater.clear();

for (DataSnapshot notatsnapshot : dataSnapshot.getChildren()) {
Notat notat = notatsnapshot.getValue(Notat.class);
notater.add(notat);


}
listNotater notatlistadapter = new listNotater(Notater.this, notater);

lvnotater.setAdapter(notatlistadapter);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

private void lagrenotat() {
String notatavn = etnotater.getText().toString().trim();


if (!TextUtils.isEmpty(notatavn)) {
String id = databaseNotater.push().getKey();

Notat notat = new Notat(id, notatavn);
databaseNotater.child(id).setValue(notat);

} else {
Toast.makeText(this, "Skriv noe", Toast.LENGTH_SHORT).show();
}

}
}


My middle Activity:



public class MainActivity extends AppCompatActivity {

public static final String jobbnavn = "jobbnavn";
public static final String jobbId = "jobbid";

Button add;
TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

add = (Button) findViewById(R.id.add);
text = (TextView) findViewById(R.id.text);

Intent intent = getIntent();


String id = intent.getStringExtra(Jobbliste.jobbId);
String navn = intent.getStringExtra(Jobbliste.jobbnavn);

text.setText(navn);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);


}
});
}
}






android firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 21:16









Frank van Puffelen

234k29381407




234k29381407










asked Nov 23 '18 at 18:17









AlexanderAlexander

247




247













  • So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

    – 0X0nosugar
    Nov 23 '18 at 18:52











  • Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

    – Alexander
    Nov 23 '18 at 19:06













  • You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

    – 0X0nosugar
    Nov 23 '18 at 19:10











  • The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

    – Alexander
    Nov 23 '18 at 19:14








  • 1





    Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

    – 0X0nosugar
    Nov 23 '18 at 19:17



















  • So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

    – 0X0nosugar
    Nov 23 '18 at 18:52











  • Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

    – Alexander
    Nov 23 '18 at 19:06













  • You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

    – 0X0nosugar
    Nov 23 '18 at 19:10











  • The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

    – Alexander
    Nov 23 '18 at 19:14








  • 1





    Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

    – 0X0nosugar
    Nov 23 '18 at 19:17

















So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

– 0X0nosugar
Nov 23 '18 at 18:52





So "Jobbliste" is your first Activity and you want to get to "MainActivity" and finally to "Notater"? I'm asking because I can't find the part in the first Activity where you start the middle Activity

– 0X0nosugar
Nov 23 '18 at 18:52













Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

– Alexander
Nov 23 '18 at 19:06







Yes that's right. I edited the code now. What happens is, I get to "MainActivity" from "Jobbliste", but not from "MainActivity" to "Notater". But it works from "Jobbliste" to "Notater" without problems.

– Alexander
Nov 23 '18 at 19:06















You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

– 0X0nosugar
Nov 23 '18 at 19:10





You mean you click the "add" Button in MainActivity and nothing happens? Or you click the "add" Button and the app crashes?

– 0X0nosugar
Nov 23 '18 at 19:10













The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

– Alexander
Nov 23 '18 at 19:14







The app crashes, and I get this error: ** java.lang.NullPointerException: Can't pass null for argument 'pathString' in child() at com.google.firebase.database.DatabaseReference.child(Unknown Source:40)**

– Alexander
Nov 23 '18 at 19:14






1




1





Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

– 0X0nosugar
Nov 23 '18 at 19:17





Looks like you forgot to put the Intent extras (id and navn) when starting the second Activity from MainActivity

– 0X0nosugar
Nov 23 '18 at 19:17












1 Answer
1






active

oldest

votes


















0














Let's compare how you start Notater



From Jobbliste in your first, working version:



listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());
startActivity(intent);

return false;
}
});


From MainActivity:



add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);
}
});


In Notater, you try to get the values for id and navn, but right now the Intent which was used to start Notater does not have any extras so both variables are null. This causes the NullPointerException.



There are two lines missing right before startActivity():



leggtil.putExtra(Jobbliste.jobbId, id);
leggtil.putExtra(Jobbliste.jobbnavn, navn);


(Please note that in order to be able to access the String variables id and navn from onClick(), you have to make them final.)






share|improve this answer
























  • This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

    – Alexander
    Nov 23 '18 at 19:51













  • @Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

    – 0X0nosugar
    Nov 23 '18 at 20:02











  • But maybe your issue can be solved if you refresh the ListView content in onResume() ?

    – 0X0nosugar
    Nov 23 '18 at 20:04











  • Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

    – Alexander
    Nov 23 '18 at 20:06











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451367%2fcant-get-actvity-to-navigate-to-another-activity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Let's compare how you start Notater



From Jobbliste in your first, working version:



listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());
startActivity(intent);

return false;
}
});


From MainActivity:



add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);
}
});


In Notater, you try to get the values for id and navn, but right now the Intent which was used to start Notater does not have any extras so both variables are null. This causes the NullPointerException.



There are two lines missing right before startActivity():



leggtil.putExtra(Jobbliste.jobbId, id);
leggtil.putExtra(Jobbliste.jobbnavn, navn);


(Please note that in order to be able to access the String variables id and navn from onClick(), you have to make them final.)






share|improve this answer
























  • This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

    – Alexander
    Nov 23 '18 at 19:51













  • @Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

    – 0X0nosugar
    Nov 23 '18 at 20:02











  • But maybe your issue can be solved if you refresh the ListView content in onResume() ?

    – 0X0nosugar
    Nov 23 '18 at 20:04











  • Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

    – Alexander
    Nov 23 '18 at 20:06
















0














Let's compare how you start Notater



From Jobbliste in your first, working version:



listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());
startActivity(intent);

return false;
}
});


From MainActivity:



add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);
}
});


In Notater, you try to get the values for id and navn, but right now the Intent which was used to start Notater does not have any extras so both variables are null. This causes the NullPointerException.



There are two lines missing right before startActivity():



leggtil.putExtra(Jobbliste.jobbId, id);
leggtil.putExtra(Jobbliste.jobbnavn, navn);


(Please note that in order to be able to access the String variables id and navn from onClick(), you have to make them final.)






share|improve this answer
























  • This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

    – Alexander
    Nov 23 '18 at 19:51













  • @Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

    – 0X0nosugar
    Nov 23 '18 at 20:02











  • But maybe your issue can be solved if you refresh the ListView content in onResume() ?

    – 0X0nosugar
    Nov 23 '18 at 20:04











  • Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

    – Alexander
    Nov 23 '18 at 20:06














0












0








0







Let's compare how you start Notater



From Jobbliste in your first, working version:



listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());
startActivity(intent);

return false;
}
});


From MainActivity:



add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);
}
});


In Notater, you try to get the values for id and navn, but right now the Intent which was used to start Notater does not have any extras so both variables are null. This causes the NullPointerException.



There are two lines missing right before startActivity():



leggtil.putExtra(Jobbliste.jobbId, id);
leggtil.putExtra(Jobbliste.jobbnavn, navn);


(Please note that in order to be able to access the String variables id and navn from onClick(), you have to make them final.)






share|improve this answer













Let's compare how you start Notater



From Jobbliste in your first, working version:



listjobber.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Jobber jobber = listjobb.get(i);

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(jobbId, jobber.getJobbId());
intent.putExtra(jobbnavn, jobber.getJobbnavn());
startActivity(intent);

return false;
}
});


From MainActivity:



add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent leggtil = new Intent(MainActivity.this, Notater.class);
startActivity(leggtil);
}
});


In Notater, you try to get the values for id and navn, but right now the Intent which was used to start Notater does not have any extras so both variables are null. This causes the NullPointerException.



There are two lines missing right before startActivity():



leggtil.putExtra(Jobbliste.jobbId, id);
leggtil.putExtra(Jobbliste.jobbnavn, navn);


(Please note that in order to be able to access the String variables id and navn from onClick(), you have to make them final.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 19:36









0X0nosugar0X0nosugar

7,41331842




7,41331842













  • This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

    – Alexander
    Nov 23 '18 at 19:51













  • @Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

    – 0X0nosugar
    Nov 23 '18 at 20:02











  • But maybe your issue can be solved if you refresh the ListView content in onResume() ?

    – 0X0nosugar
    Nov 23 '18 at 20:04











  • Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

    – Alexander
    Nov 23 '18 at 20:06



















  • This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

    – Alexander
    Nov 23 '18 at 19:51













  • @Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

    – 0X0nosugar
    Nov 23 '18 at 20:02











  • But maybe your issue can be solved if you refresh the ListView content in onResume() ?

    – 0X0nosugar
    Nov 23 '18 at 20:04











  • Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

    – Alexander
    Nov 23 '18 at 20:06

















This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

– Alexander
Nov 23 '18 at 19:51







This worked, thank you very much :) But it did work without making them final. Have I done something wrong then? Now I manage to navigate to Notater from MainActivity, but when I try to save new data from Notater to my listview (firebase) it does'nt relate it to the Jobbliste, only add a new data in firebase with no relation. Why is that`?

– Alexander
Nov 23 '18 at 19:51















@Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

– 0X0nosugar
Nov 23 '18 at 20:02





@Alexander - "But it did work without making them final." Well, my Android Studio always complains when I try to access local variables from an OnClickListener method. Maybe because without making them final one can't be exactly sure about the value at execution time? And about the firebase problem: I don't have any experience with firebase, so you'd best ask a new question about this new issue.

– 0X0nosugar
Nov 23 '18 at 20:02













But maybe your issue can be solved if you refresh the ListView content in onResume() ?

– 0X0nosugar
Nov 23 '18 at 20:04





But maybe your issue can be solved if you refresh the ListView content in onResume() ?

– 0X0nosugar
Nov 23 '18 at 20:04













Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

– Alexander
Nov 23 '18 at 20:06





Maybe I should make them final then. But anyways, you saved my day :) @0X0nosugar

– Alexander
Nov 23 '18 at 20:06




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451367%2fcant-get-actvity-to-navigate-to-another-activity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'