Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

java - java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / firebase / firestore / QueryListenOptions;(java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/firestore/QueryListenOptions;)

I did follow Youtube tutorial on how to retrieve data from Firebase Cloud Firestore at part 3. Here is the link Part3 .

(我没有按照有关如何在部分3.这里检索火力地堡云公司的FireStore数据的Youtube教程链接第三部分 。)

I changed a bit of code, from main to go to the class that will print the result of data I retrieve from Firebase, but suddenly when i try clicked button to go to the next activity it shows this error.

(我从main更改了一些代码,转到将打印从Firebase检索到的数据结果的类,但是突然间,当我尝试单击按钮转到下一个活动时,它显示此错误。)

2019-12-01 20:18:34.015 5780-5780/com.example.testingchat E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.testingchat, PID: 5780
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/firestore/QueryListenOptions;
        at com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery(FirestoreRecyclerOptions.java:108)
        at com.example.testingchat.ForumTitle.setUpRecyclerView(ForumTitle.java:45)
        at com.example.testingchat.ForumTitle.onCreate(ForumTitle.java:37)
        at android.app.Activity.performCreate(Activity.java:7009)

This is my gradle

(这是我的摇篮)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.testingchat"
        minSdkVersion 15
        multiDexEnabled true
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation "com.firebaseui:firebase-ui-firestore:3.0.0"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:21.3.0'
    implementation 'com.android.support:multidex:1.0.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

MainActivity.java

(MainActivity.java)

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "FireLog";
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button)findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ForumTitle.class);
                startActivity(intent);
            }
        });

    }
}

UserAdapter.java

(UserAdapter.java)

public class UserAdapter extends FirestoreRecyclerAdapter <Userz,UserAdapter.UserHolder>{


    /**
     * Create a new RecyclerView adapter that listens to a Firestore Query.  See
     * {@link FirestoreRecyclerOptions} for configuration options.
     *
     * @param options
     */
    public UserAdapter(FirestoreRecyclerOptions<Userz> options) {
        super(options);
    }

    @Override
    protected void onBindViewHolder(UserHolder userHolder, int i, Userz userz) {
        userHolder.textViewName.setText(userz.getName());
        userHolder.textViewStatus.setText(userz.getStatus());
        userHolder.textViewMessage.setText(userz.getMessages());
    }

    @NonNull
    @Override
    public UserHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview,parent,false);
        return new UserHolder(v);
    }

    class UserHolder extends RecyclerView.ViewHolder{
        TextView textViewName;
        TextView textViewMessage;
        TextView textViewStatus;
        public UserHolder(View itemView) {
            super(itemView);
            textViewName = itemView.findViewById(R.id.name);
            textViewMessage = itemView.findViewById(R.id.messages);
            textViewStatus = itemView.findViewById(R.id.status);
        }
    }
}

ForumTitle.java

(ForumTitle.java)

public class ForumTitle extends AppCompatActivity {
    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private CollectionReference userRef = db.collection("Users");

    private UserAdapter adapter;

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

        setUpRecyclerView();

    }

    private void setUpRecyclerView(){
        Query query = userRef.orderBy("name",Query.Direction.DESCENDING);

        FirestoreRecyclerOptions<Userz> options = new FirestoreRecyclerOptions.Builder<Userz>()
                .setQuery(query,Userz.class)
                .build();

        adapter = new UserAdapter(options);

        RecyclerView recyclerView = findViewById(R.id.my_recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        adapter.startListening();
    }

    @Override
    protected void onStop() {
        super.onStop();
        adapter.stopListening();
    }
}
  ask by MUHAMAD NUR FIKRY BIN MARJAMAL translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update the firebaseUi dependency to the following:

(将firebaseUi依赖项更新为以下内容:)

   implementation 'com.firebaseui:firebase-ui-firestore:6.1.0'

QueryListenOptions was replaced with MetadataChanges in cloud firestore version 16, you can find more information here:

(QueryListenOptions已在Cloud QueryListenOptions版本16中被MetadataChanges替换,您可以在此处找到更多信息:)

https://firebase.google.com/support/release-notes/android#version_1600

(https://firebase.google.com/support/release-notes/android#version_1600)

And it was removed from firebaseUI in version 4:

(在版本4中将其从firebaseUI中删除:)

Adopt the breaking changes from the firebase-firestore library version 16.0.0.

(采用firebase-firestore库版本16.0.0中的重大更改。)

The primary breaking change is the removal of QueryListenOptions, which has been replaced by the MetadataChanges enum.

(主要的重大更改是删除了QueryListenOptions,已将其替换为MetadataChanges枚举。)

See the firebase release notes for more information.

(有关更多信息,请参阅Firebase发行说明。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...