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

“java.lang.NullPointerException”错误(错误详细信息,文章中有)如何修复?

卢和昶
2023-03-14

我在尝试在Firebase实时数据库中注册用户时收到1-2个代码错误。更正后,我收到了这样一个错误。我在这里做了一些研究,但我没有尝试。请帮帮我。

E/AndroidRuntime:致命异常:主进程:com。实例yagoozonfirebasejava,PID:6130 java。lang.NullPointerException:尝试调用虚拟方法“void android”。小部件。文本视图。com上的空对象引用上的setText(java.lang.CharSequence)“”。实例yagoozonfirebasejava。ProfilePageAdapter。com上的onBindViewHolder(ProfilePageAdapter.java:60)。实例yagoozonfirebasejava。ProfilePageAdapter。android上的onBindViewHolder(ProfilePageAdapter.java:16)。支持v7.widget。RecyclerView$适配器。android上的onBindViewHolder(RecyclerView.java:6781)。支持v7.widget。RecyclerView$适配器。android上的bindViewHolder(RecyclerView.java:6823)。支持v7.widget。RecyclerView$回收商。在android上试用BindViewHolderByDeadline(RecyclerView.java:5752)。支持v7.widget。RecyclerView$回收商。android上的TryGetViewHolderPositionByDeadline(RecyclerView.java:6019)。支持v7.widget。RecyclerView$回收商。android上的getViewForPosition(RecyclerView.java:5858)。支持v7.widget。RecyclerView$回收商。android上的getViewForPosition(RecyclerView.java:5854)。支持v7.widget。LinearLayoutManager$布局状态。接下来(LinearLayoutManager.java:2230)在android上。支持v7.widget。LinearLayoutManager。android上的layoutChunk(LinearLayoutManager.java:1557)。支持v7.widget。LinearLayoutManager。android上的fill(LinearLayoutManager.java:1517)。支持v7.widget。LinearLayoutManager。android上的onLayoutChildren(LinearLayoutManager.java:612)。支持v7.widget。回收视图。android上的dispatchLayoutStep2(RecyclerView.java:3924)。支持v7.widget。回收视图。android上的dispatchLayout(RecyclerView.java:3641)。支持v7.widget。回收视图。android上的onLayout(RecyclerView.java:4194)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。支持限制ConstraintLayout。android上的onLayout(ConstraintLayout.java:1915)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。小部件。框架布局。android上的layoutChildren(FrameLayout.java:323)。小部件。框架布局。android上的onLayout(FrameLayout.java:261)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。小部件。线性布局。android上的setChildFrame(LinearLayout.java:1812)。小部件。线性布局。android上的layoutVertical(LinearLayout.java:1656)。小部件。线性布局。android上的onLayout(LinearLayout.java:1565)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。小部件。框架布局。android上的layoutChildren(FrameLayout.java:323)。小部件。框架布局。android上的onLayout(FrameLayout.java:261)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。小部件。线性布局。android上的setChildFrame(LinearLayout.java:1812)。小部件。线性布局。android上的layoutVertical(LinearLayout.java:1656)。小部件。线性布局。android上的onLayout(LinearLayout.java:1565)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。小部件。框架布局。android上的layoutChildren(FrameLayout.java:323)。小部件。框架布局。com上的onLayout(FrameLayout.java:261)。Android内部的政策德考维。android上的onLayout(DecorView.java:753)。看法看法android上的布局(View.java:20672)。看法视图组。android上的布局(ViewGroup.java:6194)。看法ViewRootImpl。在android上执行布局(ViewRootImpl.java:2792)。看法ViewRootImpl。在android上执行Traversals(ViewRootImpl.java:2319)。看法ViewRootImpl。android上的doTraversal(ViewRootImpl.java:1460)。看法ViewRootImpl$TraversalRunnable。在android上运行(ViewRootImpl.java:7183)。看法Choreographer$CallbackRecord。在android上运行(Choreographer.java:949)。看法编舞android上的doCallbacks(Choreographer.java:761)。看法编舞android上的doFrame(Choreographer.java:696)。看法Choreographer$FrameDisplayEventReceiver。在android上运行(Choreographer.java:935)。操作系统。处理程序。android上的handleCallback(Handler.java:873)。操作系统。处理程序。dispatchMessage(Handler.java:99)E/AndroidRuntime:at-android。操作系统。活套。android上的loop(Looper.java:193)。应用程序。ActivityThread。java上的main(ActivityThread.java:6669)。lang.reflect。方法在com上调用(本机方法)。Android内部的操作系统。RuntimeInit$MethodandArgscaler。在com上运行(RuntimeInit.java:493)。Android内部的操作系统。合子岩。main(ZygoteInit.java:858)

配置文件页面适配器代码:

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.firebase.database.DatabaseReference;

import java.util.List;

public class ProfilePageAdapter extends RecyclerView.Adapter<ProfilePageAdapter.CardDesingHolder>{

    private Context mContext;
    private List<Users> usersList;
    private DatabaseReference myRef;

    public ProfilePageAdapter(Context mContext, List<Users> kisilerListe, DatabaseReference myRef) {
        this.mContext = mContext;
        this.usersList = kisilerListe;
        this.myRef = myRef;
    }

    public class CardDesingHolder extends RecyclerView.ViewHolder {

        private TextView user_RealNameProfileAdapter;
        private TextView user_surnameProfileAdapter;
        private TextView user_emailProfileAdapter;
        private TextView user_nameProfileAdapter;
        private ImageView user_ImageViewProfileAdapter;

        public CardDesingHolder(@NonNull View itemView) {
            super(itemView);

            user_RealNameProfileAdapter = itemView.findViewById(R.id.userRealName_userCard);
            user_surnameProfileAdapter = itemView.findViewById(R.id.usersurname_userCard);
            user_emailProfileAdapter = itemView.findViewById(R.id.userEmail_userCard);
            user_ImageViewProfileAdapter = itemView.findViewById(R.id.userProfileImage_userCard);
        }
    }

    @NonNull
    @Override
    public CardDesingHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.user_card, viewGroup, false);
        return new CardDesingHolder(view);
    }

    @Override
    public void onBindViewHolder(final CardDesingHolder cardDesingHolder, int position) {
        final Users user = usersList.get(position);

        cardDesingHolder.user_emailProfileAdapter.setText("Mail : " + user.getUser_email());
        cardDesingHolder.user_surnameProfileAdapter.setText("Surname : " + user.getUser_surname());
        cardDesingHolder.user_RealNameProfileAdapter.setText("Name : " + user.getUser_name());
        cardDesingHolder.user_nameProfileAdapter.setText("Username : " + user.getUser_username());


    }

    @Override
    public int getItemCount() {
        return usersList.size();
    }
}
```


SignUp Page Code's : 
```java
package com.example.yagoozonfirebasejava;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ServerValue;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;

import java.io.IOException;
import java.util.UUID;

public class signupPage extends AppCompatActivity {
private Button btn_signupSignPage;
private EditText emailText;
private EditText passwordText;
private EditText user_surname;
private EditText user_username;
private EditText user_name;


// Database and Storage
private FirebaseAuth mAuth;
FirebaseDatabase firebaseDatabase;
DatabaseReference myRef;


private StorageReference mStorageRef;

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

        user_username = findViewById(R.id.username_signPage);
        user_surname = findViewById(R.id.surname_SignUpPage);
        user_name = findViewById(R.id.name_signPage);
        btn_signupSignPage = findViewById(R.id.btn_signSignupPage);
        emailText = findViewById(R.id.mail_signupPage);
        passwordText = findViewById(R.id.pass_signupPage);

        // Database and Storage
        // Veritabanı ve Storage
        mAuth = FirebaseAuth.getInstance();
        firebaseDatabase = FirebaseDatabase.getInstance();
        myRef = firebaseDatabase.getReference("Users");
        mStorageRef = FirebaseStorage.getInstance().getReference();


    }

    // Sign Up Method
    // Kullanıcı Kayıt etme metodu
   public void signUp(View view) {
       mAuth.createUserWithEmailAndPassword(emailText.getText().toString(), passwordText.getText().toString())
               .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                   @Override
                   public void onComplete(@NonNull Task<AuthResult> task) {
                       if (task.isSuccessful()) /* Kullanıcı girişi başarılı ise bu çalışacak */ {
                           Toast.makeText(signupPage.this, "User Created", Toast.LENGTH_SHORT).show();
                           Intent homePage = new Intent(signupPage.this, ProfilePage.class);
                           startActivity(homePage);
                           finish();

                       } else /* Kullanıcı girişi başarısız ise bu çalışacak */ {
                           Intent signBack = new Intent(signupPage.this, signupPage.class);
                           startActivity(signBack);
                           finish();
                       }

                   }
               }).addOnFailureListener(this, new OnFailureListener() {
           @Override
           public void onFailure(@NonNull Exception e) {
               Toast.makeText(signupPage.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
           }
       });

       String userName = user_name.getText().toString();
       String userSurname = user_surname.getText().toString();
       String username = user_username.getText().toString();
       String user_email = emailText.getText().toString();
       String key = myRef.push().getKey();


       Users user = new Users(key,username,userSurname,userName,user_email);

       myRef.push().setValue(user);


/*
       // Profile Image Method
       // Profil Resmi Seçme Metodu
       public void selectImage (View view){
           if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
               ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
           } else {
               Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
               startActivityForResult(gallery, 2);
           }
       }


    // Permission Control
    // İzin Kontrolü
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (requestCode == 1) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(gallery, 2);
            }
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    // Profil Resmi Seçtirme
    @Override
    protected void onActivityResult(int resultCode, @Nullable Intent data) {
        if(requestCode == 2 && resultCode == RESULT_OK &&  data != null) {
            selectedImage = data.getData();
            try {
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                profilResmi.setImageBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
*/
   }

}
```


Users Class Code's : 
```java
package com.example.yagoozonfirebasejava;

public class Users {
    private String user_id;
    private String user_name;
    private String user_username;
    private String user_surname;
    private String user_email;

    // Empty Constructor
    public Users() {
    }

    // Constructor
    public Users(String user_id, String user_name, String user_username, String user_surname, String user_email ) {
        this.user_id = user_id;
        this.user_name = user_name;
        this.user_username = user_username;
        this.user_surname = user_surname;
        this.user_email = user_email;
    }

    // Getter And Setter's

    public String getUser_id() {
        return user_id;
    }

    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public String getUser_username() {
        return user_username;
    }

    public void setUser_username(String user_username) {
        this.user_username = user_username;
    }

    public String getUser_surname() {
        return user_surname;
    }

    public void setUser_surname(String user_surname) {
        this.user_surname = user_surname;
    }

    public String getUser_email() {
        return user_email;
    }

    public void setUser_email(String user_email) {
        this.user_email = user_email;
    }

}
```

用户卡XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/userRealName_userCard"
            android:layout_marginTop="130dp"
            android:textAlignment="center"
            android:textSize="25dp"
            android:layout_width="match_parent"
            android:layout_height="41dp"
            android:text="Yılmaz Yağız" />

        <TextView
            android:id="@+id/usersurname_userCard"
            android:textAlignment="center"
            android:layout_marginTop="25dp"
            android:textSize="30dp"
            android:layout_below="@id/userRealName_userCard"
            android:layout_width="match_parent"
            android:layout_height="41dp"
            android:text="Dokumacı" />

        <ImageView
            android:id="@+id/userProfileImage_userCard"
            android:layout_marginTop="25dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/usersurname_userCard"
            tools:srcCompat="@tools:sample/avatars" />

        <TextView
            android:id="@+id/userEmail_userCard"
            android:layout_marginTop="25dp"
            android:textAlignment="center"
            android:textSize="25dp"
            android:layout_below="@id/userProfileImage_userCard"
            android:layout_width="match_parent"
            android:layout_height="41dp"
            android:text="ddismnaklda@gmail.com" />

        <TextView
            android:id="@+id/username_userCard"
            android:layout_marginTop="25dp"
            android:textAlignment="center"
            android:textSize="25dp"
            android:layout_below="@id/userEmail_userCard"
            android:layout_width="match_parent"
            android:layout_height="41dp"
            android:text="yagoo" />


    </RelativeLayout>


</LinearLayout>

共有2个答案

后安民
2023-03-14

内部onBindViewHolder

cardDesingHolder.user_emailProfileAdapter
cardDesingHolder.user_surnameProfileAdapter        
cardDesingHolder.user_RealNameProfileAdapter
cardDesingHolder.user_nameProfileAdapter

textview中的任何一个都为null

丰景同
2023-03-14

尝试添加user\u nameProfileAdapter=itemView。findViewById(R.id.userName\U userCard) 到您的卡片设计持有人

 类似资料:
  • 问题内容: 尝试连接到网站时出现400错误。 如何设置连接以显示服务器拒绝我的原因? http://jsoup.org/apidocs/org/jsoup/Connection.html 问题答案: HTTP 400是“错误请求”。这可能是服务器的问题,但这 可能 是 您的代码中 的问题。调试这些问题的最佳方法并不取决于您使用的语言:只需嗅探网络流量即可查看HTTP请求的外观。您还可以查看服务器的

  • 我有一些带有JAXB注释的类,我创建了一些实例,我需要根据我的XSD文件验证它们。当对象无效时,我应该能够得到错误的详细信息。 到目前为止,我还不走运,我知道这个类ValidationEventHandler,但显然我可以将它用于解组器类,问题是我必须验证对象,而不是原始XML。 我有这个密码: 这段代码可以工作,它将验证对象,并抛出一个异常消息,如下所示: CVC模式有效:值'123456789

  • 我正在尝试使用DOCX4j、Java11、Spring Boot2.3.5、Ubuntu18.04.5将DOCX转换为HTML,我正在Tomcat9上运行我的.war文件。 当我运行代码时,我得到这个错误。我怎么才能修好这个? 我的代码 编辑:我试着在Tomcat9、Windows10上运行同样的战争,一切都正常。有趣...但是如何在Linux-Tomcat上解决这个问题呢?(检查了tomcat/

  • 本文向大家介绍IIS7.5 显示详细错误信息的方法,包括了IIS7.5 显示详细错误信息的方法的使用技巧和注意事项,需要的朋友参考一下 使用Win7/Win2008/R2操作系统的用户在不断增加,Win7下测试程序时,如果程序出 错,IIS7会提示HTTP Error 500 - Internal Server Error (500 - 内部服务器错误) 的简单错误信息。这些简单信息对应用户来说比

  • 我有Archlinux,我尝试运行,我收到以下错误消息: 错误:.onLoad在“tcltk”的loadNamespace()中失败,详细信息:call:dyn。load(file,DLLpath=DLLpath,…)错误:无法加载共享对象'/usr/lib/R/library/tcltk/libs/tcltk。so':libtk8.6.so:无法打开共享对象文件:没有这样的文件或目录 我知道这个

  • 验证规则的错误提示信息有三种方式可以定义,如下: 使用默认的错误提示信息 如果没有定义任何的验证提示信息,系统会显示默认的错误信息,例如: namespace app\index\validate; use think\Validate; class User extends Validate { protected $rule = [ 'name' => 'requir