Android app crashes when using bundle to moving data from one to another using firestore












0














I am trying to move register number from MainActivity.java to Academics.java
I used navigation drawer to jump from one activity to another.
After using bundle to move data...While clicking the option on navigation drawer the app crashes. help me.



MainActivity.java



public class MainActivity extends AppCompatActivity {
Bundle bundle;
EditText regno,password;
ProgressDialog progress;
TextView attempt,register;
FirebaseFirestore store;
Button signin;
Integer count=5;
String Re,Pass,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress=new ProgressDialog(MainActivity.this);
store=FirebaseFirestore.getInstance();

regno=(EditText)findViewById(R.id.editText1);
password=(EditText)findViewById(R.id.editText2);
register=(TextView)findViewById(R.id.textView1);
attempt=(TextView)findViewById(R.id.textView3);
signin=(Button)findViewById(R.id.button);


signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//progress bar
progress.setTitle("Please wait");
progress.setMessage("Fetching Data..");
progress.show();
//-----------------
String INregno=regno.getText().toString();
String INpass=password.getText().toString();

if(INregno.isEmpty())
{
regno.setError("Enter the Registerno");
progress.dismiss();
}
else if(INpass.isEmpty())
{
password.setError("Enter the password");
progress.dismiss();
}
else if(count>=1)
{
//Firestore Fetching

store.collection("Students").document(regno.getText().toString()).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>()
{
@Override
public void onSuccess(DocumentSnapshot documentSnapshot)
{

Re = documentSnapshot.getString("Regno");
Pass = documentSnapshot.getString("Password");
dept = documentSnapshot.getString("Department");
if (password.getText().toString().equals(Pass) && regno.getText().toString().equals(Re))
{
finish();
progress.dismiss();
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_LONG).show();

/*Bundle intent to take data from login to other activity

*/
Intent in = new Intent(getApplicationContext(), Academic.class);
in.putExtra("regno",Re);
in.putExtra("dept",dept);
startActivity(in);
}
else
{
--count;
progress.dismiss();
Toast.makeText(getApplicationContext(), "Invalid Username and Password", Toast.LENGTH_LONG).show();
attempt.setText("No.of.Attempts: "+count);
}

}

})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{
progress.dismiss();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
else
{

progress.dismiss();
Toast.makeText(getApplicationContext(),"Reached the maximum limit of attemptsn Try later",Toast.LENGTH_SHORT).show();

}



}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent in=new Intent(MainActivity.this,Registration.class);
startActivity(in);
}
});


}
}



Academic.java



public class Academic extends AppCompatActivity {

DrawerLayout mDrawer;
ActionBarDrawerToggle mToggle;
Bundle bundle;
String regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_academic);

FirebaseFirestore db = FirebaseFirestore.getInstance();

/*Bundle arrives from Login Activity
with Regno and dept
Error raises due to the following three lines
*/
bundle = getIntent().getExtras();
regno =bundle.getString("regno");
dept=bundle.getString("dept"); //bundle receiving ends here

//Tool bar declaration
Toolbar toolbarObj = (Toolbar)findViewById(R.id.toolbar_id);
setSupportActionBar(toolbarObj);
getSupportActionBar().setTitle("Academics");

//Drawer Layout
mDrawer=(DrawerLayout)findViewById(R.id.drawer_layout);
mToggle=new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
mDrawer.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

//-----navigation selection
NavigationView nv=(NavigationView)findViewById(R.id.select_nav_option);
nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
{
case(R.id.academic):
{
finish();
Intent in = new Intent(getApplicationContext(), Academic.class);
startActivity(in);
break;
}
case(R.id.logout):
{
finish();
Intent in= new Intent(getApplicationContext(),MainActivity.class);
startActivity(in);
break;

}

case(R.id.location):
{

Intent in= new Intent(getApplicationContext(),Location.class);
startActivity(in);
break;

}
case(R.id.contact):
{
finish();
Intent in= new Intent(getApplicationContext(),Contact.class);
startActivity(in);
break;

}

}
return true;
}
});




}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{

if(mToggle.onOptionsItemSelected(item))
{
return true;
}

return super.onOptionsItemSelected(item);
}


}



Logcat error



11-20 01:02:51.669 11153-11153/com.smartinfo.techguy.smartinfodesk     W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
11-20 01:02:51.671 11153-11153/com.smartinfo.techguy.smartinfodesk E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartinfo.techguy.smartinfodesk, PID: 11153
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartinfo.techguy.smartinfodesk/com.smartinfo.techguy.smartinfodesk.Academic}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.smartinfo.techguy.smartinfodesk.Academic.onCreate(Academic.java:41)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
11-20 01:03:21.674 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: exiting
11-20 01:03:21.675 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: bye!


Help me...Thanks in Advance










share|improve this question
























  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
    – Alex Mamo
    Nov 19 '18 at 19:29










  • Logcat error posted.
    – Techguy
    Nov 19 '18 at 19:40










  • At which particular line of code are you getting this error?
    – Alex Mamo
    Nov 19 '18 at 19:41










  • check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
    – Techguy
    Nov 19 '18 at 19:43












  • It means that your Bundle is null. Are you sure you are storing something in it?
    – Alex Mamo
    Nov 19 '18 at 19:48
















0














I am trying to move register number from MainActivity.java to Academics.java
I used navigation drawer to jump from one activity to another.
After using bundle to move data...While clicking the option on navigation drawer the app crashes. help me.



MainActivity.java



public class MainActivity extends AppCompatActivity {
Bundle bundle;
EditText regno,password;
ProgressDialog progress;
TextView attempt,register;
FirebaseFirestore store;
Button signin;
Integer count=5;
String Re,Pass,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress=new ProgressDialog(MainActivity.this);
store=FirebaseFirestore.getInstance();

regno=(EditText)findViewById(R.id.editText1);
password=(EditText)findViewById(R.id.editText2);
register=(TextView)findViewById(R.id.textView1);
attempt=(TextView)findViewById(R.id.textView3);
signin=(Button)findViewById(R.id.button);


signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//progress bar
progress.setTitle("Please wait");
progress.setMessage("Fetching Data..");
progress.show();
//-----------------
String INregno=regno.getText().toString();
String INpass=password.getText().toString();

if(INregno.isEmpty())
{
regno.setError("Enter the Registerno");
progress.dismiss();
}
else if(INpass.isEmpty())
{
password.setError("Enter the password");
progress.dismiss();
}
else if(count>=1)
{
//Firestore Fetching

store.collection("Students").document(regno.getText().toString()).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>()
{
@Override
public void onSuccess(DocumentSnapshot documentSnapshot)
{

Re = documentSnapshot.getString("Regno");
Pass = documentSnapshot.getString("Password");
dept = documentSnapshot.getString("Department");
if (password.getText().toString().equals(Pass) && regno.getText().toString().equals(Re))
{
finish();
progress.dismiss();
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_LONG).show();

/*Bundle intent to take data from login to other activity

*/
Intent in = new Intent(getApplicationContext(), Academic.class);
in.putExtra("regno",Re);
in.putExtra("dept",dept);
startActivity(in);
}
else
{
--count;
progress.dismiss();
Toast.makeText(getApplicationContext(), "Invalid Username and Password", Toast.LENGTH_LONG).show();
attempt.setText("No.of.Attempts: "+count);
}

}

})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{
progress.dismiss();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
else
{

progress.dismiss();
Toast.makeText(getApplicationContext(),"Reached the maximum limit of attemptsn Try later",Toast.LENGTH_SHORT).show();

}



}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent in=new Intent(MainActivity.this,Registration.class);
startActivity(in);
}
});


}
}



Academic.java



public class Academic extends AppCompatActivity {

DrawerLayout mDrawer;
ActionBarDrawerToggle mToggle;
Bundle bundle;
String regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_academic);

FirebaseFirestore db = FirebaseFirestore.getInstance();

/*Bundle arrives from Login Activity
with Regno and dept
Error raises due to the following three lines
*/
bundle = getIntent().getExtras();
regno =bundle.getString("regno");
dept=bundle.getString("dept"); //bundle receiving ends here

//Tool bar declaration
Toolbar toolbarObj = (Toolbar)findViewById(R.id.toolbar_id);
setSupportActionBar(toolbarObj);
getSupportActionBar().setTitle("Academics");

//Drawer Layout
mDrawer=(DrawerLayout)findViewById(R.id.drawer_layout);
mToggle=new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
mDrawer.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

//-----navigation selection
NavigationView nv=(NavigationView)findViewById(R.id.select_nav_option);
nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
{
case(R.id.academic):
{
finish();
Intent in = new Intent(getApplicationContext(), Academic.class);
startActivity(in);
break;
}
case(R.id.logout):
{
finish();
Intent in= new Intent(getApplicationContext(),MainActivity.class);
startActivity(in);
break;

}

case(R.id.location):
{

Intent in= new Intent(getApplicationContext(),Location.class);
startActivity(in);
break;

}
case(R.id.contact):
{
finish();
Intent in= new Intent(getApplicationContext(),Contact.class);
startActivity(in);
break;

}

}
return true;
}
});




}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{

if(mToggle.onOptionsItemSelected(item))
{
return true;
}

return super.onOptionsItemSelected(item);
}


}



Logcat error



11-20 01:02:51.669 11153-11153/com.smartinfo.techguy.smartinfodesk     W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
11-20 01:02:51.671 11153-11153/com.smartinfo.techguy.smartinfodesk E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartinfo.techguy.smartinfodesk, PID: 11153
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartinfo.techguy.smartinfodesk/com.smartinfo.techguy.smartinfodesk.Academic}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.smartinfo.techguy.smartinfodesk.Academic.onCreate(Academic.java:41)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
11-20 01:03:21.674 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: exiting
11-20 01:03:21.675 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: bye!


Help me...Thanks in Advance










share|improve this question
























  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
    – Alex Mamo
    Nov 19 '18 at 19:29










  • Logcat error posted.
    – Techguy
    Nov 19 '18 at 19:40










  • At which particular line of code are you getting this error?
    – Alex Mamo
    Nov 19 '18 at 19:41










  • check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
    – Techguy
    Nov 19 '18 at 19:43












  • It means that your Bundle is null. Are you sure you are storing something in it?
    – Alex Mamo
    Nov 19 '18 at 19:48














0












0








0







I am trying to move register number from MainActivity.java to Academics.java
I used navigation drawer to jump from one activity to another.
After using bundle to move data...While clicking the option on navigation drawer the app crashes. help me.



MainActivity.java



public class MainActivity extends AppCompatActivity {
Bundle bundle;
EditText regno,password;
ProgressDialog progress;
TextView attempt,register;
FirebaseFirestore store;
Button signin;
Integer count=5;
String Re,Pass,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress=new ProgressDialog(MainActivity.this);
store=FirebaseFirestore.getInstance();

regno=(EditText)findViewById(R.id.editText1);
password=(EditText)findViewById(R.id.editText2);
register=(TextView)findViewById(R.id.textView1);
attempt=(TextView)findViewById(R.id.textView3);
signin=(Button)findViewById(R.id.button);


signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//progress bar
progress.setTitle("Please wait");
progress.setMessage("Fetching Data..");
progress.show();
//-----------------
String INregno=regno.getText().toString();
String INpass=password.getText().toString();

if(INregno.isEmpty())
{
regno.setError("Enter the Registerno");
progress.dismiss();
}
else if(INpass.isEmpty())
{
password.setError("Enter the password");
progress.dismiss();
}
else if(count>=1)
{
//Firestore Fetching

store.collection("Students").document(regno.getText().toString()).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>()
{
@Override
public void onSuccess(DocumentSnapshot documentSnapshot)
{

Re = documentSnapshot.getString("Regno");
Pass = documentSnapshot.getString("Password");
dept = documentSnapshot.getString("Department");
if (password.getText().toString().equals(Pass) && regno.getText().toString().equals(Re))
{
finish();
progress.dismiss();
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_LONG).show();

/*Bundle intent to take data from login to other activity

*/
Intent in = new Intent(getApplicationContext(), Academic.class);
in.putExtra("regno",Re);
in.putExtra("dept",dept);
startActivity(in);
}
else
{
--count;
progress.dismiss();
Toast.makeText(getApplicationContext(), "Invalid Username and Password", Toast.LENGTH_LONG).show();
attempt.setText("No.of.Attempts: "+count);
}

}

})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{
progress.dismiss();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
else
{

progress.dismiss();
Toast.makeText(getApplicationContext(),"Reached the maximum limit of attemptsn Try later",Toast.LENGTH_SHORT).show();

}



}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent in=new Intent(MainActivity.this,Registration.class);
startActivity(in);
}
});


}
}



Academic.java



public class Academic extends AppCompatActivity {

DrawerLayout mDrawer;
ActionBarDrawerToggle mToggle;
Bundle bundle;
String regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_academic);

FirebaseFirestore db = FirebaseFirestore.getInstance();

/*Bundle arrives from Login Activity
with Regno and dept
Error raises due to the following three lines
*/
bundle = getIntent().getExtras();
regno =bundle.getString("regno");
dept=bundle.getString("dept"); //bundle receiving ends here

//Tool bar declaration
Toolbar toolbarObj = (Toolbar)findViewById(R.id.toolbar_id);
setSupportActionBar(toolbarObj);
getSupportActionBar().setTitle("Academics");

//Drawer Layout
mDrawer=(DrawerLayout)findViewById(R.id.drawer_layout);
mToggle=new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
mDrawer.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

//-----navigation selection
NavigationView nv=(NavigationView)findViewById(R.id.select_nav_option);
nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
{
case(R.id.academic):
{
finish();
Intent in = new Intent(getApplicationContext(), Academic.class);
startActivity(in);
break;
}
case(R.id.logout):
{
finish();
Intent in= new Intent(getApplicationContext(),MainActivity.class);
startActivity(in);
break;

}

case(R.id.location):
{

Intent in= new Intent(getApplicationContext(),Location.class);
startActivity(in);
break;

}
case(R.id.contact):
{
finish();
Intent in= new Intent(getApplicationContext(),Contact.class);
startActivity(in);
break;

}

}
return true;
}
});




}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{

if(mToggle.onOptionsItemSelected(item))
{
return true;
}

return super.onOptionsItemSelected(item);
}


}



Logcat error



11-20 01:02:51.669 11153-11153/com.smartinfo.techguy.smartinfodesk     W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
11-20 01:02:51.671 11153-11153/com.smartinfo.techguy.smartinfodesk E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartinfo.techguy.smartinfodesk, PID: 11153
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartinfo.techguy.smartinfodesk/com.smartinfo.techguy.smartinfodesk.Academic}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.smartinfo.techguy.smartinfodesk.Academic.onCreate(Academic.java:41)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
11-20 01:03:21.674 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: exiting
11-20 01:03:21.675 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: bye!


Help me...Thanks in Advance










share|improve this question















I am trying to move register number from MainActivity.java to Academics.java
I used navigation drawer to jump from one activity to another.
After using bundle to move data...While clicking the option on navigation drawer the app crashes. help me.



MainActivity.java



public class MainActivity extends AppCompatActivity {
Bundle bundle;
EditText regno,password;
ProgressDialog progress;
TextView attempt,register;
FirebaseFirestore store;
Button signin;
Integer count=5;
String Re,Pass,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress=new ProgressDialog(MainActivity.this);
store=FirebaseFirestore.getInstance();

regno=(EditText)findViewById(R.id.editText1);
password=(EditText)findViewById(R.id.editText2);
register=(TextView)findViewById(R.id.textView1);
attempt=(TextView)findViewById(R.id.textView3);
signin=(Button)findViewById(R.id.button);


signin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//progress bar
progress.setTitle("Please wait");
progress.setMessage("Fetching Data..");
progress.show();
//-----------------
String INregno=regno.getText().toString();
String INpass=password.getText().toString();

if(INregno.isEmpty())
{
regno.setError("Enter the Registerno");
progress.dismiss();
}
else if(INpass.isEmpty())
{
password.setError("Enter the password");
progress.dismiss();
}
else if(count>=1)
{
//Firestore Fetching

store.collection("Students").document(regno.getText().toString()).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>()
{
@Override
public void onSuccess(DocumentSnapshot documentSnapshot)
{

Re = documentSnapshot.getString("Regno");
Pass = documentSnapshot.getString("Password");
dept = documentSnapshot.getString("Department");
if (password.getText().toString().equals(Pass) && regno.getText().toString().equals(Re))
{
finish();
progress.dismiss();
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_LONG).show();

/*Bundle intent to take data from login to other activity

*/
Intent in = new Intent(getApplicationContext(), Academic.class);
in.putExtra("regno",Re);
in.putExtra("dept",dept);
startActivity(in);
}
else
{
--count;
progress.dismiss();
Toast.makeText(getApplicationContext(), "Invalid Username and Password", Toast.LENGTH_LONG).show();
attempt.setText("No.of.Attempts: "+count);
}

}

})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{
progress.dismiss();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
else
{

progress.dismiss();
Toast.makeText(getApplicationContext(),"Reached the maximum limit of attemptsn Try later",Toast.LENGTH_SHORT).show();

}



}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent in=new Intent(MainActivity.this,Registration.class);
startActivity(in);
}
});


}
}



Academic.java



public class Academic extends AppCompatActivity {

DrawerLayout mDrawer;
ActionBarDrawerToggle mToggle;
Bundle bundle;
String regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_academic);

FirebaseFirestore db = FirebaseFirestore.getInstance();

/*Bundle arrives from Login Activity
with Regno and dept
Error raises due to the following three lines
*/
bundle = getIntent().getExtras();
regno =bundle.getString("regno");
dept=bundle.getString("dept"); //bundle receiving ends here

//Tool bar declaration
Toolbar toolbarObj = (Toolbar)findViewById(R.id.toolbar_id);
setSupportActionBar(toolbarObj);
getSupportActionBar().setTitle("Academics");

//Drawer Layout
mDrawer=(DrawerLayout)findViewById(R.id.drawer_layout);
mToggle=new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
mDrawer.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

//-----navigation selection
NavigationView nv=(NavigationView)findViewById(R.id.select_nav_option);
nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
{
case(R.id.academic):
{
finish();
Intent in = new Intent(getApplicationContext(), Academic.class);
startActivity(in);
break;
}
case(R.id.logout):
{
finish();
Intent in= new Intent(getApplicationContext(),MainActivity.class);
startActivity(in);
break;

}

case(R.id.location):
{

Intent in= new Intent(getApplicationContext(),Location.class);
startActivity(in);
break;

}
case(R.id.contact):
{
finish();
Intent in= new Intent(getApplicationContext(),Contact.class);
startActivity(in);
break;

}

}
return true;
}
});




}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{

if(mToggle.onOptionsItemSelected(item))
{
return true;
}

return super.onOptionsItemSelected(item);
}


}



Logcat error



11-20 01:02:51.669 11153-11153/com.smartinfo.techguy.smartinfodesk     W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
11-20 01:02:51.671 11153-11153/com.smartinfo.techguy.smartinfodesk E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartinfo.techguy.smartinfodesk, PID: 11153
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartinfo.techguy.smartinfodesk/com.smartinfo.techguy.smartinfodesk.Academic}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.smartinfo.techguy.smartinfodesk.Academic.onCreate(Academic.java:41)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
11-20 01:03:21.674 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: exiting
11-20 01:03:21.675 11153-11169/com.smartinfo.techguy.smartinfodesk D/dalvikvm: threadid=11: bye!


Help me...Thanks in Advance







java android firebase crash bundle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 19:43







Techguy

















asked Nov 19 '18 at 19:28









TechguyTechguy

113




113












  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
    – Alex Mamo
    Nov 19 '18 at 19:29










  • Logcat error posted.
    – Techguy
    Nov 19 '18 at 19:40










  • At which particular line of code are you getting this error?
    – Alex Mamo
    Nov 19 '18 at 19:41










  • check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
    – Techguy
    Nov 19 '18 at 19:43












  • It means that your Bundle is null. Are you sure you are storing something in it?
    – Alex Mamo
    Nov 19 '18 at 19:48


















  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
    – Alex Mamo
    Nov 19 '18 at 19:29










  • Logcat error posted.
    – Techguy
    Nov 19 '18 at 19:40










  • At which particular line of code are you getting this error?
    – Alex Mamo
    Nov 19 '18 at 19:41










  • check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
    – Techguy
    Nov 19 '18 at 19:43












  • It means that your Bundle is null. Are you sure you are storing something in it?
    – Alex Mamo
    Nov 19 '18 at 19:48
















If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
– Alex Mamo
Nov 19 '18 at 19:29




If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.
– Alex Mamo
Nov 19 '18 at 19:29












Logcat error posted.
– Techguy
Nov 19 '18 at 19:40




Logcat error posted.
– Techguy
Nov 19 '18 at 19:40












At which particular line of code are you getting this error?
– Alex Mamo
Nov 19 '18 at 19:41




At which particular line of code are you getting this error?
– Alex Mamo
Nov 19 '18 at 19:41












check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
– Techguy
Nov 19 '18 at 19:43






check Academics.java file the bundle line throws an error. Error lines were mentioned in the program comment
– Techguy
Nov 19 '18 at 19:43














It means that your Bundle is null. Are you sure you are storing something in it?
– Alex Mamo
Nov 19 '18 at 19:48




It means that your Bundle is null. Are you sure you are storing something in it?
– Alex Mamo
Nov 19 '18 at 19:48












0






active

oldest

votes











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%2f53381377%2fandroid-app-crashes-when-using-bundle-to-moving-data-from-one-to-another-using-f%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53381377%2fandroid-app-crashes-when-using-bundle-to-moving-data-from-one-to-another-using-f%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith