Я пытаюсь переместить регистрационный номер из MainActivity.java в Academics.java. Я использовал навигационный ящик для перехода от одного занятия к другому.После использования пакета для перемещения данных ... При выборе опции в окне навигации приложение вылетает.помогите мне.
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 attempts\n 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
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!
Помогите мне ... Заранее спасибо