我正在创建一个类别菜单,它将带您进入另一个子菜单。根据类别编号加载其内容。第一个类别活动显示数据库的内容,但是第二个活动不显示。
从firebase进行装载,并使用firebase-ui对其进行绑定。 结果为空白页。
我正在使用Android Studio 3.3 摇篮28
错误显示:
I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path
at void com.example.assus.orderline.SplashScreen.onCreate(android.os.Bundle) (SplashScreen.java:18)
第18行是
setContentView(R.layout.activity_splash_screen);
我的FoodList类:
package com.example.assus.orderline;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.assus.orderline.Interface.ItemClickListener;
import com.example.assus.orderline.Model.Food;
import com.example.assus.orderline.ViewHolder.FoodViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.squareup.picasso.Picasso;
public class FoodList extends AppCompatActivity {
FirebaseDatabase firebaseDatabase;
DatabaseReference food;
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
String categoryId = "";
FirebaseRecyclerAdapter<Food, FoodViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_list);
//init firebase
firebaseDatabase = FirebaseDatabase.getInstance();
food = firebaseDatabase.getReference("Food");
//Load Menu
recyclerView = findViewById(R.id.recycler_food);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
//get Home.class intent here
if(getIntent() != null ){
categoryId = getIntent().getStringExtra("CategoryId");
if(!categoryId.isEmpty()){
loadFoodList(categoryId);
}
}//end if
}
private void loadFoodList(String categoryId) {
adapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>
(Food.class, R.layout.food_item,
FoodViewHolder.class,
food.orderByChild("MenuId").equalTo(categoryId)) //like select * from Food where menuId =
{
@Override
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {
viewHolder.txtFoodName.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.imageFoodView);
final Food local = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Toast.makeText(FoodList.this, "" + local.getName(),Toast.LENGTH_LONG).show();
}
});
}
};
//set adapter
recyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
// put your code here...
}
}//end class
FoodViewHolder类:
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.assus.orderline.Interface.ItemClickListener;
import com.example.assus.orderline.R;
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView txtFoodName;
public ImageView imageFoodView;
private ItemClickListener itemClickListener;
public FoodViewHolder(@NonNull View itemView) {
super(itemView);
txtFoodName = itemView.findViewById(R.id.menu_name);
imageFoodView = itemView.findViewById(R.id.menu_image);
itemView.setOnClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
@Override
public void onClick(View v) {
itemClickListener.onClick(v, getAdapterPosition(), false);
}
}
这是我的礼物:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//add library database
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
//add library
implementation 'de.hdodenhof:circleimageview:1.2.1'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
}
这是调试后我的Logcat窗口内容
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/base.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_resources_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.assus.orderline-dIoMN-0TD-2sxqP-GVySGA==/split_lib_slice_5_a
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void com.example.assus.orderline.SplashScreen.onCreate(android.os.Bundle) (SplashScreen.java:18)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7009)
2019-02-13 12:16:33.711 10402-10402/com.example.assus.orderline I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7000)
2019-02-13 12:16:33.712 10402-10402/com.example.assus.orderline I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1214)
2019-02-13 12:16:33.712 10402-10402/com.example.assus.orderline
截屏: Category