Android 仅当从google play下载时出现空指针异常

Android 仅当从google play下载时出现空指针异常,android,android-studio,Android,Android Studio,我在我的android应用程序中遇到此空指针异常: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at a.a.a.a.l.b(SourceFile:1) at a.a.a.b.c$a.c(SourceFile:9) at a.a.

我在我的android应用程序中遇到此空指针异常:


java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at a.a.a.a.l.b(SourceFile:1)
    at a.a.a.b.c$a.c(SourceFile:9)
    at a.a.a.b.c.b(SourceFile:29)
    at androidx.recyclerview.widget.RecyclerView$f.a(SourceFile:14)
    at androidx.recyclerview.widget.RecyclerView$u.a(SourceFile:162)
我有一个android应用程序,有三个片段和一个底部栏,显示firebase数据库中的一些信息。该应用程序已经在google play中,启动前报告显示了异常。 在所有字符串对象中调用方法equals之前,我检查代码并添加if,仅当对象不为null时才调用该方法。最糟糕的是,当我检查我的设备(从android studio安装的应用程序)以进行调试时,应用程序不会崩溃。但是如果我从google play下载应用程序,它就会崩溃

下面是日志和其他文件

public class SpecialsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {


    private SpecialsViewModel specialsViewModel;
    private ImageView mExpandedImage;
    private SwipeRefreshLayout refreshLayout;
    private ExpandableSpecialsAdapter specialsAdapter;
    private RecyclerView specialsRecyclerView;
    private RecyclerView.LayoutManager layoutManager;

    public View onCreateView( @NonNull LayoutInflater inflater,
                              ViewGroup container, Bundle savedInstanceState ) {

        ((Main2Activity)getActivity()).fragmentState = MainActivityNavigationState.ShowingSpecials;

        specialsViewModel =
                ViewModelProviders.of(this).get(SpecialsViewModel.class);
        View root = inflater.inflate(R.layout.fragment_specials, container, false);

        refreshLayout = root.findViewById(R.id.swipe_refresh);
        refreshLayout.setOnRefreshListener(this);
        mExpandedImage = ((Main2Activity)getActivity()).getExpandedImage();

        specialsRecyclerView = root.findViewById(R.id.specials_recyclerview);
        specialsAdapter = new ExpandableSpecialsAdapter(getContext(), mExpandedImage);
        layoutManager = new LinearLayoutManager(getContext());

        specialsRecyclerView.setLayoutManager(layoutManager);
        specialsRecyclerView.setAdapter(specialsAdapter);

        return root;
    }

    private Specials getSpecial( QueryDocumentSnapshot document ) {
        String name = document.get("name").toString();
        String  where = document.get("where").toString();
        String fromDay = document.get("from_day").toString();
        String toDay = document.get("to_day").toString();
        String fromTime = document.get("from_hour").toString();
        String toTime = document.get("to_hour").toString();
        String pic = document.get("picture").toString();
        String description = document.get("description").toString();
        return new Specials(name, where, fromDay, toDay, fromTime, toTime, pic, description);
    }


    @Override
    public void onViewCreated( @NonNull View view, @Nullable Bundle savedInstanceState ) {
        super.onViewCreated(view, savedInstanceState);
        onRefresh();
    }

    @Override
    public void onRefresh() {
        refreshLayout.setRefreshing(true);
        specialsViewModel.getAllSpecials().observe(this, new Observer<List<ListItem>>() {
            @Override
            public void onChanged( List<ListItem> listItems ) {
                if (listItems.size()>0)
                    specialsAdapter.setData(listItems);
                else {

                    specialsAdapter.setData(new ArrayList<ListItem>());
                    Toast.makeText(getContext(), "Sorry, we don't have any specials at the moment", Toast.LENGTH_LONG).show();
                }
                refreshLayout.setRefreshing(false);

            }

        });
    }

}

经过一整夜的搜索和研究代码,多亏了@Ehsan msz的问题,我找到了问题所在。 看来优化的代码删除了一些重要的代码

我刚把这个从gradle拿走,现在一切都好了

buildTypes {
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true
            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true
        }

    }

谢谢大家。

您在哪里检查值是否为空?请将
build.gradle(模块:app)
build.gradle添加到原始问题中
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
//apply plugin: 'io.fabric'
apply plugin: "androidx.navigation.safeargs"



android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.rp.myrestaurants"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 14
        versionName "1.3"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true
            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true
        }

    }

    compileOptions {
        targetCompatibility = "1.8"
        sourceCompatibility = "1.7"
    }
    buildToolsVersion = '29.0.2'


}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'





    implementation 'com.google.firebase:firebase-core:17.2.0'
    implementation 'com.google.firebase:firebase-firestore:21.1.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    implementation 'com.google.firebase:firebase-database:19.1.0'

    //crahslitics dependecy
    // (Recommended) Add Analytics
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    // Add dependency


    implementation 'com.squareup.picasso:picasso:2.71828'


    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    def nav_version = "2.1.0-rc01"

    // Java
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"

    implementation "com.ablanco.zoomy:zoomy:1.1.0"
    implementation 'com.google.android.gms:play-services-location:17.0.0'

    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'


    implementation 'androidx.appcompat:appcompat:1.1.0'


    // Extensions = ViewModel + LiveDat



    implementation group: 'androidx.room', name: 'room-runtime', version: '2.1.0'
    //implementation "android.arch.persistence.room:compiler:2.1.0"
    annotationProcessor group: 'androidx.room', name: 'room-compiler', version: '2.1.0'

    androidTestImplementation "android.arch.persistence.room:testing:2.1.0"


    implementation "androidx.core:core-ktx:+"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"


}

apply plugin: 'com.google.gms.google-services'
repositories {
    mavenCentral()
}

buildTypes {
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true
            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true
        }

    }