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

在访问我的应用程序中的配置文件选项卡时,应用程序不断崩溃

甄阳朔
2023-03-14

因此,我的应用程序不断崩溃,我正在开发一个聊天应用程序,当我运行该应用程序并尝试访问profile选项卡时,logcat会崩溃。

当它运行的应用程序它的罚款,但只要我点击配置文件选项卡它崩溃它是罚款在第一,但一旦我添加更多的代码到配置文件活动它不断崩溃,但我需要的代码或它的变种

我是android studio的新手,欢迎您的帮助。

非常感谢。

这是logcat错误:

2022-01-25 17:49:08.570 2928-2928/com.example.ttt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ttt, PID: 2928
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ttt/com.example.ttt.ProfileActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
    at com.example.ttt.ProfileActivity.onCreate(ProfileActivity.java:71)
    at android.app.Activity.performCreate(Activity.java:7994)
    at android.app.Activity.performCreate(Activity.java:7978)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:223) 
    at android.app.ActivityThread.main(ActivityThread.java:7656) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

以下是简介活动:

package com.example.ttt;

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

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
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.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.squareup.picasso.Picasso;

public class ProfileActivity extends AppCompatActivity {


EditText mviewusername;
FirebaseAuth firebaseAuth;
FirebaseDatabase firebaseDatabase;
TextView mmovetoupdateprofile;

FirebaseFirestore firebaseFirestore;

ImageView mviewuserimageinimageview;

StorageReference storageReference;

private String ImageURIacessToken;

androidx.appcompat.widget.Toolbar mtoolbarofviewprofile;
ImageButton mbackbuttonofviewprofile;


FirebaseStorage firebaseStorage;



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

    mviewuserimageinimageview=findViewById(R.id.viewuserimageinview);
    mviewusername=findViewById(R.id.viewusername);
    mmovetoupdateprofile=findViewById(R.id.movetoupdateprofile);
    firebaseFirestore=FirebaseFirestore.getInstance();
    mtoolbarofviewprofile=findViewById(R.id.toolbarofviewprofile);
    mbackbuttonofviewprofile=findViewById(R.id.backbuttonofviewprofile);
    firebaseDatabase=FirebaseDatabase.getInstance();
    firebaseAuth=FirebaseAuth.getInstance();
    firebaseStorage=FirebaseStorage.getInstance();


    setSupportActionBar(mtoolbarofviewprofile);

    mbackbuttonofviewprofile.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View view)
        {
            finish();
        }
    });


    storageReference=firebaseStorage.getReference();
    storageReference.child("Images").child(firebaseAuth.getUid()).child("Profile Pic").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            ImageURIacessToken=uri.toString();
            Picasso.get().load(uri).into(mviewuserimageinimageview);

        }
    });

    DatabaseReference databaseReference=firebaseDatabase.getReference(firebaseAuth.getUid());
    databaseReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            UserProfile muserprofile=snapshot.getValue(UserProfile.class);
            mviewusername.setText(muserprofile.getUsername());
        }

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

            Toast.makeText(getApplicationContext(),"Failed To Fetch",Toast.LENGTH_SHORT).show();
        }
    });


    mmovetoupdateprofile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent=new Intent(ProfileActivity.this,UpdateProfile.class);
            intent.putExtra("nameofuser",mviewusername.getText().toString());
            startActivity(intent);
        }
    });




}


@Override
protected void onStop() {
    super.onStop();
    DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid());
    documentReference.update("status","Offline").addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            Toast.makeText(getApplicationContext(),"Now User is Offline",Toast.LENGTH_SHORT).show();
        }
    });



}

@Override
protected void onStart() {
    super.onStart();
    DocumentReference documentReference=firebaseFirestore.collection("Users").document(firebaseAuth.getUid());
    documentReference.update("status","Online").addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            Toast.makeText(getApplicationContext(),"Now User is Online",Toast.LENGTH_SHORT).show();
        }
    });

}
}

共有1个答案

陆甫
2023-03-14

这就是你的问题所在

TextView mmovetoupdateprofile;

mmovetoupdateprofile是xml中的ImageButton,而不是Textview

 类似资料:
  • 我尝试了一个显示其他响应的测试用例,我将一步一步地解释它: > 我在我的设备上安装了MDM配置文件,这提示我安装了一个应用程序,并且我成功地安装了它。应用程序已进入“应用程序中的配置文件”部分。 然后我手动删除了应用程序。

  • 我的应用程序打开与启动屏幕正常,但不能继续到主屏幕和崩溃!我正在尝试使tablayout(代码中没有错误)

  • 问题内容: 好的,所以我不想在这里展开一场圣战,但是我们正在努力巩固处理应用程序配置文件的方式,我们正在努力决定采用哪种最佳方法。目前,我们分发的每个应用程序都在使用其自己的临时配置文件,无论是属性文件(ini样式),XML还是JSON(目前仅在内部使用!)。 目前,我们的大多数代码是Java,因此我们一直在研究Apache Commons Config ,但是我们发现它非常冗长。我们还研究了XM

  • 我正在Android中创建一个带有导航视图的tabLayout。我想将图标设置到选项卡布局的选项卡上。当我使用setIcon函数时,应用程序抛出一个空指针异常并崩溃。请帮帮我. 在android.app.activityThread.-wrap11(activityThread.java)在android.app.activityThread$H.HandleMessage(activityThr

  • 注意:在我添加广告之前,我的应用程序运行良好,使用相同的方法 当我试图将adview添加到我的应用程序时,它会使我的应用程序崩溃,所以我删除了它,但仍然给我这个这是logcat 10-12 21:33:19.765 4993-4993/com。fm360。almorfis E/AndroidRuntime:致命异常:主进程:com。fm360。阿尔莫菲斯,PID:4993爪哇。lang.Runti

  • 我创建了一个应用程序,在Android marshmallow中崩溃,而在under版本中我的应用程序正常工作。 这怎么可能?这是我的清单代码: 这是分级代码: 我读到你必须在代码中修改一些东西,使其与AndroidMarshmallow兼容。 我该如何解决问题呢?