My Android App crashes as soon as I click a button, while it is connected to Firebase. I copied the same application in a new Project, without connecting it to Firebase and it didn't crashed. How can I avoid the crashing of the App
Here is my app gradle:
The Error I get in the Logcat:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.paragleid_app/com.example.paragleid_app.Regestration}: java.lang.IllegalAccessException: void com.example.paragleid_app.Regestration.<init>() is not accessible from java.lang.Class<android.app.Instrumentation>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2850)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.IllegalAccessException: void com.example.paragleid_app.Regestration.<init>() is not accessible from java.lang.Class<android.app.Instrumentation>
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1182)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2840)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
LoginActvity:
theName = Name.getText().toString();
thePassword = Passwort.getText().toString();
Registieren.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openRegestration();
}
});
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference myCoRef = db.collection("User");
db.collection("Users")
.whereEqualTo("Password", thePassword) // task to query if name and Password matches
.whereEqualTo("name", theName)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()) {
//QuerySnapshot result = task.getResult();
Toast toast = Toast. makeText(getApplicationContext(),"Login Successful", Toast. LENGTH_SHORT);
openVereinsUebersicht();
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Login wasn't successful", Toast.LENGTH_LONG);
}
}
});
}
});
As soon as this line comes to operation: the App crashes
public void openRegestration () {
Intent intent = new Intent(this, Regestration.class);
startActivity(intent);
}
Related
This is like my first or second StackOverflow question, so bear with me.
I want to get the Firebase UID upon login success. However, I get an error with getCurrentUser.getUid() being null.
Below is the following code
mAuth.signInWithEmailAndPassword(inputemail.getText().toString(), inputPassword.getText().toString())
.addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
mUser=mAuth.getCurrentUser();
userID = mUser.getUid();
DocumentReference docRef = db.collection("userDB").document(userID);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
#Override
public void onComplete(#NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
String val = document.getString("type");
if(val.equals("client")){
if (mAuth.getCurrentUser().isEmailVerified()){
progressDialog.dismiss();
sendUserToNextActivity();
Toast.makeText(Login.this, "Login Success!", Toast.LENGTH_SHORT).show();
}else{
progressDialog.dismiss();
FirebaseAuth.getInstance().signOut();
Toast.makeText(Login.this, "Please verify email first!", Toast.LENGTH_SHORT).show();
}
}else{
FirebaseAuth.getInstance().signOut();
progressDialog.dismiss();
Toast.makeText(Login.this, "Employees are not permmitted!", Toast.LENGTH_SHORT).show();
}
} else {
}
}
});
}
});
Here is the full error log.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bottomnavigationview, PID: 27109
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
at com.example.bottomnavigationview.Login$3$1.onComplete(Login.java:86)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks##18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Which points at
userID = mUser.getUid();
Is there another way or a fix where I can get the UID upon successful login? I heard about onAuthStateChanged but I can't seem to get a grasp of it.
[Edit]
It is noted that mAuth and mUser has been declared within the class.
FirebaseAuth mAuth; FirebaseUser mUser;
As well as mAuth=FirebaseAuth.getInstance() within onCreate.
Your code assumes that the sign-in succeeded, which is not necessarily the case inside onComplete.
You need to handle both success and failure, like this:
mAuth.signInWithEmailAndPassword(inputemail.getText().toString(), inputPassword.getText().toString())
.addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
mUser=mAuth.getCurrentUser();
userID = mUser.getUid();
...
}
else {
Log.e("Firebase", "Sign in failed", task.getException());
}
}
...
Now if the sign-in fails, check the logcat output for the root cause, and fix that.
This question already has answers here:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
(5 answers)
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 1 year ago.
I'm following this tutorial to explore Firebase and use email authentication using
three java classes
MainActivity
RegisterActivity
ProfileActivity
and
three layout views.
activity_main.xml
activity_register.xml
profilepage.xml
[Youtube tutorial]1
I'm getting
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.firebaselearning/com.example.firebaselearning.RegisterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
full error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firebaselearning, PID: 8008
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.firebaselearning/com.example.firebaselearning.RegisterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.firebaselearning.RegisterActivity.onCreate(RegisterActivity.java:60)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
following are the codes (excluding gradle because i don't think it's where error originates from)
MainActivity.java
public class MainActivity extends AppCompatActivity {
//views
Button mRegisterBtn, mLogInBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialise view
mRegisterBtn = findViewById(R.id.registerbutton);
mLogInBtn = findViewById(R.id.login);
//handle register button click
mRegisterBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//start register activity
startActivity(new Intent(MainActivity.this, RegisterActivity.class));
}
});
}
}
RegisterActivity.java
public class RegisterActivity extends AppCompatActivity {
//views
EditText mEmailET, mPassword;
Button mRegistrationBTN;
//progressbar to display progress which registering
ProgressDialog progressDialog;
//declare instance of fireAuth
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//actionbar and its title
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Create Account");
//enable back button
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
//init
mEmailET = findViewById(R.id.editTextTextEmailAddress);
mPassword = findViewById(R.id.editTextTextPassword);
mRegistrationBTN = findViewById(R.id.registerbutton);
//initialising firebaseAuth instance
mAuth = FirebaseAuth.getInstance();
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Registering user ...");
//handle register btn click
mRegistrationBTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//input email, password
String email = mEmailET.getText().toString().trim();
String password = mPassword.getText().toString().trim();
//validate
if(Patterns.EMAIL_ADDRESS.matcher(email).matches()){
//show error and focus to edittext
mEmailET.setError("Invalid Email");
mEmailET.setFocusable(true);
}else if (password.length()<6){
//set error and focus to password
mPassword.setError("Password length must be at least 6 characters");
mPassword.setFocusable(true);
}else{
//register the user
registerUser(email,password);
}
}
});
}
private void registerUser(String email, String password){
//email and password is valid ,shows progress dialog and start registering user
progressDialog.show();
mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, dismiss dialog and start register activity
progressDialog.dismiss();
FirebaseUser user = mAuth.getCurrentUser();
assert user != null;
Toast.makeText(RegisterActivity.this,"Registered..."+user.getEmail(), Toast.LENGTH_SHORT).show();
startActivity(new Intent(RegisterActivity.this, ProfileActivity.class));
finish();
} else {
// If sign in fails, display a message to the user.
progressDialog.dismiss();
Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
}
}) .addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
//error, dismiss progrss dialog and get and show error message
progressDialog.dismiss();
Toast.makeText(RegisterActivity.this,""+e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onSupportNavigateUp() {
onBackPressed(); //go previous activity on clicking back
return super.onSupportNavigateUp();
}
}
I've reverified that names of my xml files are same .
Error arose due to referencing register button from activity_main.xml layout which is view of MainActivity , from RegisterActivity which has another register button in it's view of activity_register.xml
sorry to waste your time
.
the register button from activity_main thus wasn't initialised in the Register.java
I am working on my App, and till now the App runs fine despite some small errors. The user can sign in, login and change his profile information. In the last steps, I added a function to delete userinformation. The delete function works so the userinformation gets deleted from FirebaseAuth and the FirebaseRealtimeDatabase but the app crashes.
Before I already had problems with passing null values, maybe thats related to the problem.
Update: I changed the code and tried to implement the suggestions but its still crashing...
Logcat:
09-18 16:28:20.474 23342-23342/com.example.login E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.login, PID: 23342
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.login.UserProfil.getVorname()' on a null object reference
at com.example.login.ProfileActivity$1.onDataChange(ProfileActivity.java:59)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##19.0.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##19.0.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##19.0.0:55)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:234)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Some part of my ProfileActivity
firebaseAuth=FirebaseAuth.getInstance();
firebaseDatabase= FirebaseDatabase.getInstance();
if (firebaseAuth.getCurrentUser() != null) {
firebaseDatabase= FirebaseDatabase.getInstance();
final DatabaseReference databaseReference = firebaseDatabase.getReference("Users").child(firebaseAuth.getUid());
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) ;
{
UserProfil userProfil = dataSnapshot.getValue(UserProfil.class);
profilVorname.setText(userProfil.getVorname());
profilNachname.setText(userProfil.getNachname());
profilStrasse.setText(userProfil.getStrasse());
profilHNr.setText(userProfil.getHnr());
profilPlz.setText(userProfil.getPlz());
profilStadt.setText(userProfil.getStadt());
profilLand.setText(userProfil.getLand());
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(ProfileActivity.this, "Database Error", Toast.LENGTH_SHORT).show();
}
});
}else{
startActivity(new Intent(ProfileActivity.this,NavActivity.class));
}
Some part of my UpdatProfilActivity
loeschen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final DatabaseReference databaseReference = firebaseDatabase.getReference("Users").child(firebaseAuth.getUid());
databaseReference.removeValue();
FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser();
user.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
// firebaseAuth.signOut();
// startActivity(new Intent(UpdateProfilActivity.this, MainActivity.class));
//finish();
}
}
});
}
});
This is most probably due to that the 'dataSnapshot' object is null when onDataChange() is triggered upon deletion; you can return if it is null
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (!dataSnapshot.exists())
return;
UserProfil userProfil = dataSnapshot.getValue(UserProfil.class);
profilVorname.setText(userProfil.getVorname());
profilNachname.setText(userProfil.getNachname());
profilStrasse.setText(userProfil.getStrasse());
profilHNr.setText(userProfil.getHnr());
profilPlz.setText(userProfil.getPlz());
profilStadt.setText(userProfil.getStadt());
profilLand.setText(userProfil.getLand());
}
When addValueEventListener is used, then it listens on every event what happened with current reference. And when you delete it then dataSnapshot in listener comes null and on getVorname() exception is thrown.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I'm having difficulty understanding something with my app.
I am using Firebase to provide user authentication which works fine until I try it on other phones/devices.
When I put in the email and password and press 'Login', the app crashes and the log gives the following:
FATAL EXCEPTION: main Process: com.example.android.frapp, PID: 14822
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zzb(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
at com.example.android.frapp.MainLoginActivity.startSiginIn(MainLoginActivity.java:105)
at com.example.android.frapp.MainLoginActivity.access$000(MainLoginActivity.java:23)
at com.example.android.frapp.MainLoginActivity$2.onClick(MainLoginActivity.java:65)
at android.view.View.performClick(View.java:5197)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
It's all happening from my main login class (which I have provided below):
public class MainLoginActivity extends AppCompatActivity {
private EditText mEmailField;
private EditText mPasswordField;
private Button mLoginBtn;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private boolean isUserClickedBackButton = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_login);
mAuth = FirebaseAuth.getInstance();
mEmailField = (EditText) findViewById(R.id.emailField);
mPasswordField = (EditText) findViewById(R.id.passwordField);
mLoginBtn = (Button) findViewById(R.id.loginBtn);
// connection to user authentication on firebase (database)
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null){
startActivity(new Intent(MainLoginActivity.this, MainActivity.class));
}
}
};
mLoginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startSiginIn();
}
});
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
// code for exiting from app by using back button on login page
public void onBackPressed() {
//moveTaskToBack(true);
if (!isUserClickedBackButton){
Toast.makeText(this, "Press back again to exit", Toast.LENGTH_SHORT).show();
isUserClickedBackButton = true;
} else {
System.exit(0); // exits right out of app
super.onBackPressed();
}
}
// for login
private void startSiginIn() {
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
Toast.makeText(MainLoginActivity.this, "Please input email and password", Toast.LENGTH_LONG).show();
} else {
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (!task.isSuccessful())
Toast.makeText(MainLoginActivity.this, "Sign in problem. Please check email" +
" and password", Toast.LENGTH_LONG).show();
}
});
}
}
}
As I say, it works perfect on my main device but doesn't when I install and try to login on other devices. And it also works fine on the emulator.
I've tried searching for similar problems but can't find any.
Has anyone got any ideas?
Thanks
If your authentication process works fine on your phone/emulator but you get that error when testing on another device it means that most likely that device does not have Google Play Services installed. Make sure it is installed correctly and try again.
I have a problem,
I can't get my button to work
On click it should switch from MainActivity to Login
Both classes work fine without the Button,
but now, as I brought in the Button, it keeps crashing.
What am I doing wrong?
This Button, which brings me from login to Mainactivity, works just fine:
public class login extends Activity {
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.login);
b1 = (Button)findViewById(R.id.button);
ed1 = (EditText)findViewById(R.id.editText);
ed2 = (EditText)findViewById(R.id.editText2);
b2 = (Button)findViewById(R.id.button2);
tx1 = (TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(ed1.getText().toString().equals("admin") && ed2.getText().toString().equals("admin")) {
Toast.makeText(getApplicationContext(),"Redirecting...",Toast.LENGTH_SHORT).show();
Intent i = new Intent(login.this, MainActivity.class);
startActivity(i);
}
else{
Toast.makeText(getApplicationContext(), "Fehlerhafte Eingabe",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
Button code
StrgS.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
{
Toast.makeText(getApplicationContext(), "Goodbye", Toast.LENGTH_LONG).show();
Intent j = new Intent(MainActivity.this, login.class);
startActivity(j);
}
}
});
}
}
Error Code
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cris.zeiterfassungv2, PID: 10555
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cris.zeiterfassungv2/com.example.cris.zeiterfassungv2.MainActivity}: android.view.InflateException: Binary XML file line #0: Can't convert value at index 6 to dimension: type=0x12
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #0: Can't convert value at index 6 to dimension: type=0x12
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 6 to dimension: type=0x12
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:730)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7797)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1976)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1874)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1872)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.cris.zeiterfassungv2.MainActivity.onCreate(MainActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Thank you