• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

java.lang.string error

akhil0007

Lurker
please help in getting rid of this error...
 

Attachments

  • error.png
    error.png
    133.1 KB · Views: 149
Please show all the code for class RegisterActivity.java. Need to see the declaration of variable loadingBar.
The error indicates that either a) There's no method setTitle() defined or b) you're using the wrong method parameters for this method, on the class relevant to variable loadingBar.
 
package com.example.anew.mychat;


import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class RegisterActivity extends AppCompatActivity {

private FirebaseAuth mAuth;

private Toolbar mToolbar;
private ProgressBar loadingBar;

private EditText RegisterUserName;
private EditText RegisterUserEmail;
private EditText RegisterUserPassword;
private Button CreateAccountButton;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

mAuth = FirebaseAuth.getInstance();

mToolbar = (Toolbar) findViewById(R.id.register_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Sign Up");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

RegisterUserName = (EditText) findViewById(R.id.register_name);
RegisterUserEmail = (EditText) findViewById(R.id.register_email);
RegisterUserPassword = (EditText) findViewById(R.id.register_password);
CreateAccountButton = (Button) findViewById(R.id.create_account_button);
loadingBar = new ProgressBar(this);


CreateAccountButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
String name = RegisterUserName.getText().toString();
String email = RegisterUserEmail.getText().toString();
String password = RegisterUserPassword.getText().toString();

RegisterAccount (name, email, password);
}
});
}


private void RegisterAccount(String name, String email, String password) {
if (TextUtils.isEmpty(name)){
Toast.makeText(this, "Please write your name", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(email)){
Toast.makeText(this, "Please write your email", Toast.LENGTH_LONG).show();
}

if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please write your password", Toast.LENGTH_LONG).show();
}

else{

loadingBar.setTitle("Creating New Account");
loadingBar.setMessage("Please wait, while we are creating acccount for you.");
loadingBar.show();

mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
else {
Toast.makeText(RegisterActivity.this, "Error Occured Try Again....", Toast.LENGTH_SHORT).show();
}

loadingBar.dismiss();
}
});
}
}
}
 
Please show all the code for class RegisterActivity.java. Need to see the declaration of variable loadingBar.
The error indicates that either a) There's no method setTitle() defined or b) you're using the wrong method parameters for this method, on the class relevant to variable loadingBar.

Code:
package com.example.anew.mychat;


import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class RegisterActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;

    private Toolbar mToolbar;
    private ProgressBar loadingBar;

    private EditText RegisterUserName;
    private EditText RegisterUserEmail;
    private EditText RegisterUserPassword;
    private Button CreateAccountButton;

    [USER=1021285]@override[/USER]
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        mAuth = FirebaseAuth.getInstance();

        mToolbar = (Toolbar) findViewById(R.id.register_toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setTitle("Sign Up");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        RegisterUserName = (EditText) findViewById(R.id.register_name);
        RegisterUserEmail = (EditText) findViewById(R.id.register_email);
        RegisterUserPassword = (EditText) findViewById(R.id.register_password);
        CreateAccountButton = (Button) findViewById(R.id.create_account_button);
        loadingBar = new ProgressBar(this);


        CreateAccountButton.setOnClickListener(new View.OnClickListener() {
            [USER=1021285]@override[/USER]
            public void onClick(View v) {
                String name = RegisterUserName.getText().toString();
                String email = RegisterUserEmail.getText().toString();
                String password = RegisterUserPassword.getText().toString();

                RegisterAccount (name, email, password);
            }
        });
    }


    private void RegisterAccount(String name, String email, String password) {
        if (TextUtils.isEmpty(name)){
            Toast.makeText(this, "Please write your name", Toast.LENGTH_LONG).show();
        }

        if (TextUtils.isEmpty(email)){
            Toast.makeText(this, "Please write your email", Toast.LENGTH_LONG).show();
        }

        if (TextUtils.isEmpty(password)){
            Toast.makeText(this, "Please write your password", Toast.LENGTH_LONG).show();
        }

        else{

            loadingBar.setTitle("Creating New Account");
            loadingBar.setMessage("Please wait, while we are creating acccount for you.");
            loadingBar.show();

            mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                [USER=1021285]@override[/USER]
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()){
                        Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                        mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(mainIntent);
                        finish();
                    }
                    else {
                        Toast.makeText(RegisterActivity.this, "Error Occured Try Again....", Toast.LENGTH_SHORT).show();
                    }

                    loadingBar.dismiss();
                }
            });
        }
    }
}
 
Last edited by a moderator:
Your object loadingBar is ProgressBar. Android ProgressBar does not have methods setTitle() and dismiss();
To "setTitle", If you want to show some title above loadingBar, just add TextView in layout and use setText() method.
To "dismiss", if you want to hide loadingBar, use setVisibility(Visibility.INVISIBLE) method.
 
Back
Top Bottom