Following is my code : I am sending the jSON object from one activity to another Activity.
// In LoginActivity
Intent intent = new Intent(LoginActivity.this,EmpLoginActivity.class);
startActivity(intent);
intent.putExtra("data",jsonObject.toString());
In EmpLoginActivty.java
try {
JSONObject jsonObject = new JSONObject(getIntent().getStringExtra("data"));
tv1.setText(jsonObject.getString("name"));
tv2.setText(jsonObject.getString("type"));
tv3.setText(jsonObject.getString("hours"));
} catch (JSONException e) {
e.printStackTrace();
}
Error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.krish.emp/com.example.krish.emp.EmpLoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference