在我的home.java中---> loadMenu()---> onBindViewHolder ---> onClick 将进入Foodlist.java,但出现白屏,它将进入 回到应用程序的开始...看起来好像没什么问题 我的代码..我检查我的数据库...所有引用设置正确...
请帮助它花费太多时间,但我无法解决此问题
Logcat错误:-
2019-03-07 01:59:06.851 1818-1902/? E/AudioFlinger: not enough memory for AudioTrack size=131296
2019-03-07 01:59:06.851 1818-1902/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
2019-03-07 01:59:06.852 2698-10162/com.google.android.googlequicksearchbox:search E/IAudioFlinger: createRecord returned error -12
2019-03-07 01:59:06.852 2698-10162/com.google.android.googlequicksearchbox:search E/AudioRecord: AudioFlinger could not create record track, status: -12
2019-03-07 01:59:06.853 2698-10162/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -12.
2019-03-07 01:59:06.854 2698-10162/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
2019-03-07 02:06:30.094 2698-10162/com.google.android.googlequicksearchbox:search E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
2019-03-07 02:06:30.592 2698-10162/com.google.android.googlequicksearchbox:search E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
2019-03-07 02:06:32.136 1923-1929/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-03-07 02:06:32.470 1923-2490/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-03-07 02:06:34.786 2773-10408/com.google.android.gms.persistent E/NetworkScheduler: Invalid component specified.
2019-03-07 02:06:44.633 2118-2138/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:06:56.052 1837-1837/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-03-07 02:06:59.290 2118-2138/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:07:08.808 2118-2795/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:07:24.257 1765-1805/? E/storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
2019-03-07 02:07:56.100 1837-1837/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-03-07 02:08:00.009 2118-2138/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:08:04.433 2698-11141/com.google.android.googlequicksearchbox:search E/EntrySyncManager: Cannot determine account name: drop request
2019-03-07 02:08:04.435 2698-11141/com.google.android.googlequicksearchbox:search E/NowController: Failed to access data from EntryProvider. ExecutionException.
java.util.concurrent.ExecutionException: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3
at com.google.common.util.concurrent.d.eA(SourceFile:85)
Process: com.example.eatit, PID: 11146
com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: description
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-database@@16.1.0:545)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@16.1.0:476)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@16.1.0:317)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@16.1.0:418)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.1.0:214)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@16.1.0:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@16.1.0:212)
at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:29)
at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:15)
at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:35)
at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:106)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:122)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1888)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-03-07 02:09:10.175 2118-2220/system_process E/InputDispatcher: channel '74f4010 com.example.eatit/com.example.eatit.FoodList (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-03-07 02:09:10.179 2118-2220/system_process E/InputDispatcher: channel 'ab330dc com.example.eatit/com.example.eatit.home (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-03-07 02:09:10.179 2118-2220/system_process E/InputDispatcher: channel 'a639adf com.example.eatit/com.example.eatit.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-03-07 02:09:11.542 1923-1929/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-03-07 02:09:11.759 1923-2490/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-03-07 02:09:13.191 2773-10841/com.google.android.gms.persistent E/NetworkScheduler: Invalid component specified.
2019-03-07 02:09:23.230 2118-2138/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:
2019-03-07 02:09:24.260 1765-1805/? E/storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
2019-03-07 02:09:56.160 1837-1837/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-03-07 02:10:00.030 2118-2138/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:10:09.273 2118-2797/system_process E/memtrack: Couldn't load memtrack module
2019-03-07 02:10:24.261 1765-1805/? E/storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
2019-03-07 02:10:44.248 2773-2773/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null
2019-03-07 02:10:44.279 2773-2773/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null
2019-03-07 02:10:44.570 11252-11275/com.google.android.apps.messaging E/.apps.messagin: The String#value field is not present on Android versions >= 6.0
2019-03-07 02:10:44.714 11239-11239/com.google.android.gms.ui E/.android.gms.u: The String#value field is not present on Android versions >= 6.0
2019-03-07 02:10:44.847 11252-11275/com.google.android.apps.messaging E/Bugle: P2pConversationSuggestionsUtil: Problem linking Smart Reply JNIs.
2019-03-07 02:10:44.848 11252-11275/com.google.android.apps.messaging E/Bugle: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/system/app/PrebuiltBugle/PrebuiltBugle.apk"],nativeLibraryDirectories=[/system/app/PrebuiltBugle/lib/x86, /system/app/PrebuiltBugle/PrebuiltBugle.apk!/lib/x86, /system/lib, /system/lib]]] couldn't find "libhobbes_jni.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
at java.lang.System.loadLibrary(System.java:1669)
at dgm.<clinit>(SourceFile:609)
at cuo.a(SourceFile:7)
at llj.a(SourceFile:10)
at bso.am(SourceFile:502)
at buh.o(SourceFile:46)
at bui.run(Unknown Source:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
2019-03-07 02:10:44.923 11252-11252/com.google.android.apps.messaging E/FirebaseInstanceId: Failed to start service while in background: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.google.android.apps.messaging cmp=com.google.android.apps.messaging/.fcm.BugleFirebaseInstanceIDService (has extras) }: app is in background uid UidRecord{df14836 u0a44 RCVR idle change:uncached procs:1 seq(0,0,0)}
2019-03-07 02:10:45.493 11306-11324/com.google.android.apps.messaging:rcs E/s.messaging:rc: The String#value field is not present on Android versions >= 6.0
2019-03-07 02:10:45.667 2773-10190/com.google.android.gms.persistent E/NetworkScheduler: Invalid component specified.
2019-03-07 02:10:56.171 1837-1837/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-03-07 02:11:00.016 2118-2138/system_process E/memtrack: Couldn't load memtrack module
home.java
public class home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
FirebaseDatabase database;
DatabaseReference category;
TextView txtFullName;
RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter;
FirebaseRecyclerOptions<Category> options;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Menu");
setSupportActionBar(toolbar);
//ini Firebase
database=FirebaseDatabase.getInstance();
category=database.getReference("Category");
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//set name for users
View headerView=navigationView.getHeaderView(0);
txtFullName=headerView.findViewById(R.id.txtFullName);
txtFullName.setText(Common.currentUser.getName());
//load menu
recycler_menu=findViewById(R.id.recycler_menu);
recycler_menu.setHasFixedSize(true);
layoutManager=new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
loadMenu();
}
private void loadMenu() {
options = new FirebaseRecyclerOptions.Builder<Category>()
.setQuery(category, Category.class)
.build();
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
@Override
public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.menu_item, parent, false);
return new MenuViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull MenuViewHolder viewHolder, int position, @NonNull Category model) {
viewHolder.txtMenuName.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
//Get CategoryId and send to new Activity
Intent foodList=new Intent(home.this,FoodList.class);
//because CategoryId is key, so we just get key of the item
foodList.putExtra("CategoryId",adapter.getRef(position).getKey());
// ContextCompat.startForegroundService(home.this,foodList);
startActivity(foodList);
}
});
}
};
recycler_menu.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_menu) {
// Handle the camera action
} else if (id == R.id.nav_cart) {
} else if (id == R.id.nav_order) {
} else if (id == R.id.nav_logout) {
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
FooList.java
意图进入FooList.java
package com.example.eatit;
import android.nfc.Tag;
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.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.example.eatit.Interface.ItemClickListener;
import com.example.eatit.Model.Food;
import com.example.eatit.ViewHolder.FoodViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
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 {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference foodList;
String categoryId = "";
//or maybe
//String categoryId=" ";
FirebaseRecyclerAdapter<Food, FoodViewHolder> adapter;
FirebaseRecyclerOptions<Food> options;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_list);
//Firebase
database = FirebaseDatabase.getInstance();
foodList = database.getReference("Food");
recyclerView = findViewById(R.id.recycler_food);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
//Get Intent her
if (getIntent() != null)
categoryId = getIntent().getStringExtra("CategoryId");
if (!categoryId.isEmpty() && categoryId != null) {
loadListFood(categoryId);
}
}
private void loadListFood(String categoryId) {
// Query query1 = FirebaseDatabase.getInstance().getReference("Food")
// .orderByChild("MenuId").equalTo(categoryId);
Query query1 = foodList.orderByChild("MenuId").equalTo(categoryId);
options = new FirebaseRecyclerOptions.Builder<Food>()
.setQuery(query1, Food.class)
.build();
adapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(options) {
@Override
public FoodViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.food_item, parent, false);
return new FoodViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull FoodViewHolder holder, int position, @NonNull Food model) {
holder.food_name.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage()).into(holder.food_image);
final Food clickItem = model;
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Toast.makeText(FoodList.this, "" + clickItem.getName(), Toast.LENGTH_LONG).show();
}
});
}
};
Log.d("TAG", "" + adapter.getItemCount());
recyclerView.setAdapter(adapter);
}
// Also override the following methods.
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
}
Food.java
package com.example.eatit.Model;
public class Food {
public String Name,Image,Description,Price,Discount,MenuId;
public Food() {
}
public Food(String name, String image, String description, String price, String discount, String menuId) {
Name = name;
Image = image;
Description = description;
Price = price;
Discount = discount;
MenuId = menuId;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getPrice() {
return Price;
}
public void setPrice(String price) {
Price = price;
}
public String getDiscount() {
return Discount;
}
public void setDiscount(String discount) {
Discount = discount;
}
public String getMenuId() {
return MenuId;
}
public void setMenuId(String menuId) {
MenuId = menuId;
}
}
ItemClickListener.java
其界面
package com.example.eatit.Interface;
import android.view.View;
public interface ItemClickListener {
void onClick(View view,int position,boolean isLongClick);
}
FoodViewHolder.java
package com.example.eatit.ViewHolder;
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.eatit.Interface.ItemClickListener;
import com.example.eatit.R;
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView food_name;
public ImageView food_image;
private ItemClickListener itemClickListener;
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public FoodViewHolder(@NonNull View itemView) {
super(itemView);
food_name=itemView.findViewById(R.id.food_name);
food_image=itemView.findViewById(R.id.food_image);
}
@Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition(),false);
}
}