I need to go to the second activity, but when I click the button, it will write to me:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.application/com.example.application.Firebase}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2367) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418) at android.app.ActivityThread.access$800(ActivityThread.java:152) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5341) 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:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException a at android.app.Activity.performCreate(Activity.java:5350) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
This is Firebase activity:
public class Firebase extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mlistView = (ListView) findViewById(R.id.listView);
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://example.firebase/Users");
FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(
this,
String.class,
android.R.layout.simple_list_item_1,
databaseReference
) {
@Override
protected void populateView(View v, String model, int position) {
TextView textView = (TextView) v.findViewById(android.R.id.text1);
textView.setText(model);
}
};
mlistView.setAdapter(firebaseListAdapter);
}
}
This is the first activity:
public class DashBoard extends AppCompatActivity implements View.OnClickListener {
private TextView txtWelcome;
private EditText input_new_password;
private Button btnChangePass,btnLogout;
private RelativeLayout activity_dashboard;
private FirebaseAuth auth;
private Button mbtnIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
//View
txtWelcome = (TextView)findViewById(R.id.dashboard_welcome);
input_new_password = (EditText)findViewById(R.id.dashboard_new_password);
btnChangePass = (Button)findViewById(R.id.dashboard_btn_change_pass);
btnLogout = (Button)findViewById(R.id.dashboard_btn_logout);
activity_dashboard = (RelativeLayout)findViewById(R.id.activity_dash_board);
mbtnIntent = (Button) findViewById(R.id.btnIntent);
btnChangePass.setOnClickListener(this);
btnLogout.setOnClickListener(this);
//Init Firebase
auth = FirebaseAuth.getInstance();
//Session check
if(auth.getCurrentUser() != null)
txtWelcome.setText("Welcome , "+auth.getCurrentUser().getEmail());
mbtnIntent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(DashBoard.this), Firebase.class);
startActivity(intent);
}
});
}
@Override
public void onClick(View view) {
if(view.getId() == R.id.dashboard_btn_change_pass)
changePassword(input_new_password.getText().toString());
else if(view.getId() == R.id.dashboard_btn_logout)
logoutUser();
}
private void logoutUser() {
auth.signOut();
if(auth.getCurrentUser() == null)
{
startActivity(new Intent(DashBoard.this,MainActivity.class));
finish();
}
}
private void changePassword(String newPassword) {
FirebaseUser user = auth.getCurrentUser();
user.updatePassword(newPassword).addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful())
{
Snackbar snackBar = Snackbar.make(activity_dashboard,"Password changed",Snackbar.LENGTH_SHORT);
snackBar.show();
}
}
});
}
}
This is manifest.xml :`
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DashBoard" />
<activity android:name=".ForgotPassword" />
<activity android:name= ".Firebase"/>
<activity android:name=".SignUp"></activity>
</application>
`
What should I write?