2017-03-13 3 views
0

私のフラグメントでバターナイフ8.5.1を使用しています&アプリケーションの作成エラー:java.lang.IllegalStateException:バインディングはすでにクリアされています。以下 は、私のコードの一部です:バグナイフ8.5.1フラグメントのエラー

ファイル名:BaseFragment: ....

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    if (mView == null && context != null) { 
     mView = inflater.inflate(getLayoutId(), container, false); 
     if (savedInstanceState != null) { 
      onRestoreInstanceState(savedInstanceState); 
     } 
     unbinder = ButterKnife.bind(this, mView); 
     initParams(); 
    } else if (mView != null) { 
     ViewGroup parent = (ViewGroup) mView.getParent(); 
     if (parent != null) { 
      parent.removeView(mView); 
     } 
    } 
    return mView; 
} 
@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
     unbinder.unbind(); 


} 

... 誰もが今までこのような問題に出会い、助けて?ありがとうございました !

答えて

1

あなたの行が実行されないので、それは次のとおりです。

unbinder = ButterKnife.bind(this, mView); 

おそらくあなたのコードfulfitないので、条件:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    unbinder = ButterKnife.bind(this, mView); 
    if (mView == null && context != null) { 
     mView = inflater.inflate(getLayoutId(), container, false); 
     if (savedInstanceState != null) { 
      onRestoreInstanceState(savedInstanceState); 
     } 
     initParams(); 
    } else if (mView != null) { 
     ViewGroup parent = (ViewGroup) mView.getParent(); 
     if (parent != null) { 
      parent.removeView(mView); 
     } 
    } 
    return mView; 
} 
@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
     unbinder.unbind(); 


} 
:それバインド

if (mView == null && context != null) 

このような状況の外に

または、ButterKnifeがバインドされているかどうかは何とか確認できます。 fragmentで使用する

+1

、私のコードは、これを確実にするために修正されました正しい行で実行されています!それは動作します、あなたに感謝!@Mij – dukeking

+0

それは動作しているので、答えを受け入れてください;) – miljon

0

適切な方法: "unbinder = ButterKnife.bind(これ、MVIEW);" 私はミスを犯した

private Unbinder unbinder; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout 
    View view = inflater.inflate(R.layout.content_main, container, false); 

    unbinder = ButterKnife.bind(this, view); 

    return view; 
} 

@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
    unbinder.unbind(); 
} 
関連する問題