ViewHolder视图在创建时不得附加。确保您没有将'true'传递给LayoutInflater.inflate(...,boolean attachToRoot)的attachToRoot参数
它开始发生而没有任何解释。如何解决此错误?
EditProfileFragment指出错误的地方
public class EditProfileFragment extends Fragment implements GoogleApiClient.OnConnectionFailedListener {
//Screen elements
private ImageView photoImageView;
private TextView nameTextView;
private EditText editDescr;
private List<Spinner> spinners = new ArrayList<Spinner>();
private List<Chip> tagsSugestoes = new ArrayList<>();
private List<ChipsInput> mChipsInputList;
private User user;
private List<List<Chip>> listaTags = new ArrayList<>();
private List<String> listaCategorias;
private FirebaseUser fbUser = Util.fbUser;
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_edit_profile, container, false);
//Fill the Chip's list with 4 chipsInput
mChipsInputList = new ArrayList<ChipsInput>();
mChipsInputList.add(rootView.findViewById(R.id.chipsInput1));
mChipsInputList.add(rootView.findViewById(R.id.chipsInput2));
mChipsInputList.add(rootView.findViewById(R.id.chipsInput3));
mChipsInputList.add(rootView.findViewById(R.id.chipsInput4));
//Setting elements
photoImageView = rootView.findViewById(R.id.photoImageView);
nameTextView = rootView.findViewById(R.id.nameTextView);
Button btLogout = rootView.findViewById(R.id.btLogout);
editDescr = rootView.findViewById(R.id.editDescricao);
//Set the spinner's list with 4 spinners
spinners.add(rootView.findViewById(R.id.spinner1));
spinners.add(rootView.findViewById(R.id.spinner2));
spinners.add(rootView.findViewById(R.id.spinner3));
spinners.add(rootView.findViewById(R.id.spinner4));
getUserFromFB();
//Initialize Firebase Auth
Util.mFirebaseAuth = FirebaseAuth.getInstance();
Util.mDatabaseRef.child("tagsSuggestions").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
tagsSugestoes = new ArrayList<Chip>();
for (DataSnapshot snap : dataSnapshot.getChildren()){
Chip chip = snap.getValue(Chip.class);
tagsSugestoes.add(chip);
for(int i=0; i<mChipsInputList.size(); i++){
mChipsInputList.get(i).setFilterableList(tagsSugestoes);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
listaCategorias = new ArrayList<String>();
//Fill spinners with categories and set if the user already has it set
Util.mDatabaseRef.child("categories").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
listaCategorias.add("Selecione uma categoria");
for (DataSnapshot snap : dataSnapshot.getChildren()){
listaCategorias.add(snap.getKey());
}
for (int i=0; i<spinners.size(); i++){
if(user.getCategorias() != null && user.getCategorias().size() > i)
spinners.get(i).setSelection(4);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, listaCategorias);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinners.get(i).setAdapter(adapter);
if(user.getCategorias() != null && user.getCategorias().size() > i)
spinners.get(i).setSelection(adapter.getPosition(user.getCategorias().get(i).getCategoria()));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
//Handle input chips
for(int i=0; i<mChipsInputList.size(); i++){
final int finalI = i;
mChipsInputList.get(i).addChipsListener(new ChipsInput.ChipsListener() {
@Override
public void onChipAdded(ChipInterface chip, int newSize) {
}
@Override
public void onChipRemoved(ChipInterface chip, int newSize) {
}
@Override
public void onTextChanged(CharSequence text) {
if(text.length()>0){
if(text.charAt(text.length()-1) == ' '){
String texto = text.toString();
if(!texto.trim().isEmpty())
mChipsInputList.get(finalI).addChip(texto.trim(), null);
text = "";
}}
}
});
}
Button btUpdate = rootView.findViewById(R.id.btUpdate);
btUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<Chip> listChip;
//user = new User();
List<Interesse> interesse = new ArrayList<Interesse>();
user.setCategorias(interesse);
//Adding tags Suggestions to a helping String list
List<String> tagsSugestoesSTR = new ArrayList<String>();
for(int i=0; i<tagsSugestoes.size(); i++){
tagsSugestoesSTR.add(tagsSugestoes.get(i).getLabel().trim());
}
//Handle chips and spinners by each spinner
for(int i=0; i<spinners.size(); i++){
listChip = new ArrayList<Chip>();
if(!spinners.get(i).getSelectedItem().equals("Selecione uma categoria")){
if(mChipsInputList.get(i).getSelectedChipList().size()>0 && mChipsInputList.get(i) !=null)
for(int j=0; j<mChipsInputList.get(i).getSelectedChipList().size(); j++){
listChip.add(new Chip(mChipsInputList.get(i).getSelectedChipList().get(j).getLabel()));
}
user.getCategorias().add(new Interesse(listChip, spinners.get(i).getSelectedItem().toString()));
List<String> listaSTR = new ArrayList<String>();
//Add Chips texts to helping String list
for(int j=0; j<listChip.size(); j++){
listaSTR.add(listChip.get(j).getLabel().trim());
}
//Verify if suggestion is already on database (if it's not then add)
for(int j=0; j<listaSTR.size(); j++){
if(!tagsSugestoesSTR.contains(listaSTR.get(j).trim())){
tagsSugestoes.add(listChip.get(j));
}
}
}
}
Util.mDatabaseRef.child("tagsSuggestions").setValue(tagsSugestoes);
updateProfile();
}
});
btLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
logOut();
}
});
return rootView;
}
//Get user from Firebase Database
private void getUserFromFB() {
Util.mUserDatabaseRef.child(Util.fbUser.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
user = dataSnapshot.getValue(User.class);
if(user == null){
user = new User();
user.setNome(Util.fbUser.getDisplayName());
user.setUid(Util.fbUser.getUid());
Localizacao localizacao = new Localizacao(Util.getLatitude(), Util.getLongitude());
user.setLocalizacao(localizacao);
List<Interesse> listaCategorias = new ArrayList<Interesse>();
List<Chip> chipList = new ArrayList<Chip>();
listaCategorias.add(new Interesse(chipList, "Selecione uma categoria"));
listaCategorias.add(new Interesse(chipList, "Selecione uma categoria"));
listaCategorias.add(new Interesse(chipList, "Selecione uma categoria"));
listaCategorias.add(new Interesse(chipList, "Selecione uma categoria"));
user.setCategorias(listaCategorias);
user.setFotoPerfil(Util.fbUser.getPhotoUrl().toString());
Util.mUserDatabaseRef.child(Util.fbUser.getUid()).setValue(user);
}else{
getUserProfile();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public void onStart() {
super.onStart();
Util.mFirebaseAuth.addAuthStateListener(Util.mFirebaseAuthListener);
}
@Override
public void onPause() {
super.onPause();
Util.googleApiClient.stopAutoManage(getActivity());
Util.googleApiClient.disconnect();
}
public void goLogInScreen() {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onStop() {
super.onStop();
if (Util.mFirebaseAuthListener != null) {
Util.mFirebaseAuth.removeAuthStateListener(Util.mFirebaseAuthListener);
}
}
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
public void logOut() {
//Logout Facebook
Util.mFirebaseAuth.signOut();
LoginManager.getInstance().logOut();
goLogInScreen();
}
//Get, if there is, spinners and chips data
private void getUserProfile(){
setBasicInfo();
Localizacao localizacao = new Localizacao(Util.getLatitude(), Util.getLongitude());
Util.getmUserDatabaseRef().child(Util.getFbUser().getUid()).child("localizacao").setValue(localizacao);
if (user.getCategorias() != null) {
for (int i = 0; i < user.getCategorias().size(); i++) {
spinners.get(i).setSelection(listaCategorias.indexOf(user.getCategorias().get(i).getCategoria()));
if(user.getCategorias().get(i).getTags()!=null)
for(int j=0; j<user.getCategorias().get(i).getTags().size(); j++){
mChipsInputList.get(i).addChip(user.getCategorias().get(i).getTags().get(j));
}
}
}
editDescr.setText(user.getDescricao(), TextView.BufferType.EDITABLE);
/*if(user.getTags() != null){
for (int i=0; i<user.getTags().size(); i++){
for (int j=0; j<user.getTags().get(i).size(); j++){
mChipsInputList.get(i).addChip(user.getTags().get(i).get(j).getLabel(), null);
}
}}*/
}
//Set Basic Info -- Age, Name and Photo
private void setBasicInfo() {
if(user.getIdade() > 0){
if(user.getNome()!=null){
nameTextView.setText(user.getNome() + ", " + user.getIdade());
}else{
nameTextView.setText(fbUser.getDisplayName() + ", " + user.getIdade());
}
}else{
nameTextView.setText(Util.fbUser.getDisplayName());
}
Glide.with(getApplicationContext()).load(user.getFotoPerfil()).into(photoImageView);
}
@Override
public void onResume() {
super.onResume();
}
private void updateProfile(){
if(!editDescr.getText().toString().equals(""))
user.setDescricao(editDescr.getText().toString());
//user.setFotoPerfil();
//user.setListaTags(listaTags);
Util.mUserDatabaseRef.child(Util.fbUser.getUid()).setValue(user);
Toast.makeText(getApplicationContext(), "Perfil atualizado",Toast.LENGTH_SHORT).show();
listaTags.clear();
}
}
请,有人知道真正导致此错误的原因吗?我知道有一个 这里有很多类似的问题,但是没有一种解决方案有效 为了我。它显然是无故发生的
错误日志
E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID '1063390927169899' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}
I/art: Do partial code cache collection, code=42KB, data=61KB
I/art: After code cache collection, code=40KB, data=59KB
Increasing code cache capacity to 256KB
W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.xandi.amicer, PID: 16325
java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6687)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.layoutDisappearingViews(ChipsLayoutManager.java:767)
at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.onLayoutChildren(ChipsLayoutManager.java:731)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
at android.view.View.measure(View.java:19759)
at android.support.v4.widget.NestedScrollView.measureChildWithMargins(NestedScrollView.java:1450)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:516)
at com.pchmn.materialchips.views.ScrollViewMaxHeight.onMeasure(ScrollViewMaxHeight.java:47)
at android.view.View.measure(View.java:19759)
at android.support.v4.widget.NestedScrollView.measureChildWithMargins(NestedScrollView.java:1450)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:516)
at com.pchmn.materialchips.views.ScrollViewMaxHeight.onMeasure(ScrollViewMaxHeight.java:47)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:642)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1296)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:340)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19759)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19759)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1632)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:809)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6124)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)
at android.view.View.measure(View.java:19759)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2283)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1370)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1258)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6348)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
SectionPageAdapter
package com.example.xandi.amicer;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class SectionPagerAdapter extends FragmentPagerAdapter {
public SectionPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
TabPerfil tabPerfil = new TabPerfil();
return tabPerfil;
case 1:
TabHome tabHome = new TabHome();
return tabHome;
case 2:
TabGrupos tabGrupos = new TabGrupos();
return tabGrupos;
default:
return null;
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position){
switch (position){
case 0:
return "PERFIL";
case 1:
return "HOME";
case 2:
return "GRUPOS";
}
return null;
}
}