当前位置: 首页 > 知识库问答 >
问题:

无法解决符号链接

舒永嘉
2023-03-14

我在这行有一个错误:最终用户=新用户(地址、确认密码、用户电子邮件、密码、电话号码、用户名、链接);

错误为“无法解决符号链接”

private DatabaseReference Userdatabase;
private StorageReference storageReference;
private FirebaseAuth firebaseAuth;

private StorageTask mUploadTask;

private Uri imageUri;

ImageView imageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    imageView = (ImageView) findViewById(R.id.imageView);

    firebaseAuth = FirebaseAuth.getInstance();

    Userdatabase = FirebaseDatabase.getInstance().getReference("User");

    progressDialog = new ProgressDialog(Signup.this);

    storageReference = FirebaseStorage.getInstance().getReference("Seller");

    signupButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RegisterAccount();

        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectImage();
        }
    });
}

public void selectImage() {
    Intent photoPickerIntent = new Intent();
    photoPickerIntent.setType("image/*");
    photoPickerIntent.setAction(Intent.ACTION_PICK);
    startActivityForResult(photoPickerIntent, PICK_IMAGE_REQUEST);
}

private String getFileExtension(Uri uri) {
    ContentResolver cR = getContentResolver();
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    return mime.getExtensionFromMimeType(cR.getType(uri));
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {


        imageUri = data.getData();
        Picasso.with(this).load(imageUri).into(imageView);

    }
}


public void RegisterAccount() {

    final String email = emailText.getText().toString();
    final String username = nameText.getText().toString();

    if ((TextUtils.isEmpty(address))) {
        addressText.setError("address is required");
        addressText.requestFocus();
        return;
    }

    AddUser(email, username, pass, phone, comfirmpass, address);

}

public void AddUser(final String UserEmail, final String Username, final String Password,
                    final String PhoneNumber, final String confirmPassword, final String Address) {

    String email = UserEmail.replace(".", ",");

    Userdatabase = FirebaseDatabase.getInstance().getReference("User").child(email);


    Userdatabase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {

                String value = dataSnapshot.getValue(String.class);

                Log.i(TAG, "UserEmail : " + value + " Had Already Exist");

                Toasty.warning(getApplicationContext(), "The Email you use already Exist !", Toast.LENGTH_SHORT, true).show();
                return;
            }


            if (!dataSnapshot.exists()) {
                if (imageUri != null) {
                  final  StorageReference fileReference = storageReference.child(System.currentTimeMillis()
                            + "." + getFileExtension(imageUri));



                    mUploadTask = fileReference.putFile(imageUri)
                            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                @Override
                                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                    fileReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                                        @Override
                                        public void onSuccess(Uri downloadUri) {
                                            String link = downloadUri.toString();
                                            Toast.makeText(Signup.this, "Register successful", Toast.LENGTH_LONG).show();
                                            final User user = new User(Address, confirmPassword, UserEmail, Password, PhoneNumber, Username,
                                                    link);
                                            Userdatabase.setValue(user);
                                        }
                                    });
                                }
                            });
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            return;
        }
    });

    firebaseAuth.createUserWithEmailAndPassword(UserEmail, Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            progressDialog.dismiss();

            if (!task.isSuccessful()) {
                Log.i(TAG, "Buyer FirebaseAuth Register : Fail");
                Toasty.error(getApplicationContext(), "The Email you use already Exist !", Toast.LENGTH_SHORT, true).show();
                } else {
                Log.i(TAG, "Buyer FirebaseAuth Register : Success");
                UserEmail.replace(".", ",");
                final User user = new User(Address, confirmPassword, UserEmail, Password, PhoneNumber, Username,link);
                Userdatabase.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        if (!dataSnapshot.exists()) {
                            Userdatabase.setValue(user);
                            Log.i(TAG, "FirebaseDatabase Add Buyer : Success");
                            Toasty.success(getApplicationContext(), "Register Complete", Toast.LENGTH_SHORT, true).show();
                            }
                            }
                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {
                        Log.w(TAG, "Database Error");
                        }
                        });
                }
                }
                });
}

我已经删除了一些代码,如果你需要更多细节,请在下面留下评论。有人能帮忙吗?非常感谢你的帮助

共有2个答案

仲孙子辰
2023-03-14

您将收到该错误,因为您的声明:

String link = downloadUri.toString();

超出范围。在onComplete()方法中,不能简单地使用addsuccesslistener中声明的字符串链接,因为它的作用域完全不同。字符串链接只能在声明它的范围内看到,n。除此之外,这两种方法都具有异步行为。所以,即使你把这个变量变成一个全局变量,它也不能解决问题。我能看到的最简单的修复方法是在onComplete()方法中使用链接作为空字符串:

final User user = new User(
    Address,
    confirmPassword,
    UserEmail,
    Password,
    PhoneNumber,
    Username,
    "" //empty String
);

当你得到它时,相应地更新。

更多信息请参见此处。

翟修明
2023-03-14

在类的开头声明链接与其他变量,然后在需要时设置链接。它无法解析符号链接,因为它不存在于您调用它的上下文中。

private DatabaseReference Userdatabase;
private StorageReference storageReference;
private FirebaseAuth firebaseAuth;
private String link;

private StorageTask mUploadTask;

private Uri imageUri;

ImageView imageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    imageView = (ImageView) findViewById(R.id.imageView);

    firebaseAuth = FirebaseAuth.getInstance();

    Userdatabase = FirebaseDatabase.getInstance().getReference("User");

    progressDialog = new ProgressDialog(Signup.this);

    storageReference = FirebaseStorage.getInstance().getReference("Seller");

    signupButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RegisterAccount();

        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectImage();
        }
    });
}

public void selectImage() {
    Intent photoPickerIntent = new Intent();
    photoPickerIntent.setType("image/*");
    photoPickerIntent.setAction(Intent.ACTION_PICK);
    startActivityForResult(photoPickerIntent, PICK_IMAGE_REQUEST);
}

private String getFileExtension(Uri uri) {
    ContentResolver cR = getContentResolver();
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    return mime.getExtensionFromMimeType(cR.getType(uri));
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {


        imageUri = data.getData();
        Picasso.with(this).load(imageUri).into(imageView);

    }
}


public void RegisterAccount() {

    final String email = emailText.getText().toString();
    final String username = nameText.getText().toString();

    if ((TextUtils.isEmpty(address))) {
        addressText.setError("address is required");
        addressText.requestFocus();
        return;
    }

    AddUser(email, username, pass, phone, comfirmpass, address);

}

public void AddUser(final String UserEmail, final String Username, final String Password,
                    final String PhoneNumber, final String confirmPassword, final String Address) {

    String email = UserEmail.replace(".", ",");

    Userdatabase = FirebaseDatabase.getInstance().getReference("User").child(email);


    Userdatabase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {

                String value = dataSnapshot.getValue(String.class);

                Log.i(TAG, "UserEmail : " + value + " Had Already Exist");

                Toasty.warning(getApplicationContext(), "The Email you use already Exist !", Toast.LENGTH_SHORT, true).show();
                return;
            }


            if (!dataSnapshot.exists()) {
                if (imageUri != null) {
                  final  StorageReference fileReference = storageReference.child(System.currentTimeMillis()
                            + "." + getFileExtension(imageUri));



                    mUploadTask = fileReference.putFile(imageUri)
                            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                @Override
                                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                    fileReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                                        @Override
                                        public void onSuccess(Uri downloadUri) {
                                            link = downloadUri.toString();
                                            Toast.makeText(Signup.this, "Register successful", Toast.LENGTH_LONG).show();
                                            final User user = new User(Address, confirmPassword, UserEmail, Password, PhoneNumber, Username,
                                                    link);
                                            Userdatabase.setValue(user);
                                        }
                                    });
                                }
                            });
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            return;
        }
    });

    firebaseAuth.createUserWithEmailAndPassword(UserEmail, Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            progressDialog.dismiss();

            if (!task.isSuccessful()) {
                Log.i(TAG, "Buyer FirebaseAuth Register : Fail");
                Toasty.error(getApplicationContext(), "The Email you use already Exist !", Toast.LENGTH_SHORT, true).show();
                } else {
                Log.i(TAG, "Buyer FirebaseAuth Register : Success");
                UserEmail.replace(".", ",");
                final User user = new User(Address, confirmPassword, UserEmail, Password, PhoneNumber, Username,link);
                Userdatabase.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        if (!dataSnapshot.exists()) {
                            Userdatabase.setValue(user);
                            Log.i(TAG, "FirebaseDatabase Add Buyer : Success");
                            Toasty.success(getApplicationContext(), "Register Complete", Toast.LENGTH_SHORT, true).show();
                            }
                            }
                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {
                        Log.w(TAG, "Database Error");
                        }
                        });
                }
                }
                });
}
 类似资料:
  • 代码运行,但无法获得函数、类等的建议。 谢谢

  • 我创建了一个虚拟项目来理解基于卡片的布局。不幸的是,我无法解决RecyclerView上的符号错误。我对编程还是个新手,不明白哪里出了问题。将依赖项添加到生成文件:

  • 我正在尝试使用以下命令在ADLS(Azure)上的数据库增量表上创建符号链接。 失败,并出现以下错误:< code语句中的错误:NoSuchTableException:在数据库“schema_name”中找不到表或视图“dbfs:/file path”;

  • 问题内容: 我正在按照以下链接实施Firebase Messaging,以将消息发送到多个设备 https://firebase.google.com/docs/cloud-messaging/android/send- multiple#build_send_requests 我几乎完成了实现,但停留在最后阶段(构建发送请求) 在下面的代码中 我遇到了错误 也在线 当我按住Ctrl键并单击sen

  • 问题内容: 我正在尝试为我的应用添加loginfacebook。但是,当我添加执行此操作所需的存储库时。它导致了错误。AndroidJUnit4现在无法解析。 ExampleInstrumentedTest.java 这是我的build:gradle(app) 问题答案: 尝试 添加以下上面的依赖项部分

  • 问题内容: 在我的项目中,我遇到了一个错误: 检索项目的父项时出错:找不到与给定名称“ android:TextAppearance.Material.Widget.Button.Inverse”匹配的资源。 然后我尝试使用以下方法修复它: 但是后来我得到了错误: 无法解析符号NameValuePair android 如何解决这个错误? 问题答案: 是已弃用并已被删除的软件包的一部分,这是您正在