gpt4 book ai didi

java - 类 xxx 中的构造函数 xxx 不能应用于给定类型;

转载 作者:行者123 更新时间:2023-12-01 19:31:45 26 4
gpt4 key购买 nike

我正在 YouTube 视频的帮助下构建一个 Android 项目,当我尝试构建它时,它给出了以下错误消息。

error: constructor User in class User cannot be applied to given types;

required: String,String,String,String,Uri

found: String,String

reason: actual and formal argument lists differ in length

我在视频上做了完全相同的事情,现在我不明白为什么它会给我这样的错误。这是有错误的行。代码中星号之间的行已用红色下划线表示。

Common.loggedUser = **new User(firebaseUser.getUid(), firebaseUser.getEmail())**;
user_information.child(Common.loggedUser.**getUid**())
.setValue(Common.loggedUser);
 Paper.book().write(Common.USER_UID_SAVE_KEY, Common.loggedUser.**getUid**());
tokens.child(firebaseUser.getUid())
.setValue(InstanceIdResult.**getToken**());

这是我的完整代码


import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.data.model.User;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.single.PermissionListener;
import com.mynewrealtimelocationtracker.Utils.Common;

import java.util.Arrays;
import java.util.List;

import io.paperdb.Paper;

public class MainActivity extends AppCompatActivity {

DatabaseReference user_information;
private static final int MY_REQUEST_CODE = 4477; //any number you want
List<AuthUI.IdpConfig> providers;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Paper.init(this);

//Init firebase
user_information = FirebaseDatabase.getInstance().getReference(Common.USER_INFORMATION);

//Init provider
providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build()
);

//Request permission location
Dexter.withActivity(this)
.withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
.withListener(new PermissionListener() {
@Override
public void onPermissionGranted(PermissionGrantedResponse response) {
showSignInOptions();
}

@Override
public void onPermissionDenied(PermissionDeniedResponse response) {
Toast.makeText(MainActivity.this,"You must accept permissionto use app",Toast.LENGTH_SHORT).show();
}

@Override
public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {

}
}).check();

}

private void showSignInOptions() {
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),MY_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_REQUEST_CODE){
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == RESULT_OK){
final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
//Check if user exist on database
user_information.orderByKey()
.equalTo(firebaseUser.getUid())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() == null) //If user is not exist
{
if (!dataSnapshot.child(firebaseUser.getUid()).exists()) //If key uid is not exist
{
Common.loggedUser = new User(firebaseUser.getUid(), firebaseUser.getEmail()); //--> Error
//Add to database
user_information.child(Common.loggedUser.getUid()) //->Error
.setValue(Common.loggedUser);
}
}
else // If user is available
{
Common.loggedUser = dataSnapshot.child(firebaseUser.getUid()).getValue(User.class);
}

// Save UID to storage to update location from background
Paper.book().write(Common.USER_UID_SAVE_KEY, Common.loggedUser.getUid()); //->Error
updateToken(firebaseUser);
setupUI();
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}
}
}

private void setupUI() {
//Navigate Home
startActivity(new Intent(MainActivity.this, HomeActivity.class));
}

private void updateToken(final FirebaseUser firebaseUser) {
final DatabaseReference tokens = FirebaseDatabase.getInstance()
.getReference(Common.TOKENS);

//Get Token
FirebaseInstanceId.getInstance().getInstanceId()
.addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
tokens.child(firebaseUser.getUid())
.setValue(InstanceIdResult.getToken()); //->Error
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}

这是我的用户类

package com.mynewrealtimelocationtracker.Model;

import java.util.HashMap;

public class User {
private String uid, email;
private HashMap<String, User> acceptList; //List user friend

public User() {
}

public User(String uid, String email) {
this.uid = uid;
this.email = email;
acceptList = new HashMap<>();
}

public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public HashMap<String, User> getAcceptList() {
return acceptList;
}

public void setAcceptList(HashMap<String, User> acceptList) {
this.acceptList = acceptList;
}
}

最佳答案

您从 com.firebase.ui.auth.data.model 导入了 User,但您的类位于 com.mynewrealtimelocationtracker.Model 。更改导入。

关于java - 类 xxx 中的构造函数 xxx 不能应用于给定类型;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59518090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com