当尝试将片段注入字段时,我得到以下异常:
Reason: java.lang.UnsupportedOperationException: You may only
use @InjectFragment on fields descended from type Fragment
我也尝试从RoboFragment
派生我的片段,但没有任何运气。
附带问题:甚至可以将roboguice 3.0b与导航抽屉片段一起使用吗?如果,我是以正确的方式将其作为正常片段进行威胁吗?
代码摘录
@ContentView(activity_main)
public class MainActivity extends RoboActivity
implements BoardsDrawerFragment.BoardsDrawerCallbacks
{
@InjectFragment(fragment_boards_drawer)
private BoardsDrawerFragment _boardsDrawerFragment;
}
public class BoardsDrawerFragment extends Fragment {
}
调用堆栈
java.lang.UnsupportedOperationException: You may only use @InjectFragment on fields descended from type Fragment
at roboguice.inject.ViewListener.hear(ViewListener.java:76)
at com.google.inject.internal.MembersInjectorStore.createWithListeners(MembersInjectorStore.java:102)
at com.google.inject.internal.MembersInjectorStore.access$000(MembersInjectorStore.java:34)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:42)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:39)
at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at com.google.inject.internal.MembersInjectorStore.get(MembersInjectorStore.java:65)
at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:950)
... 19 more
答案 0 :(得分:0)
您应该提供片段的 id ,例如:
@InjectFragment(R.id.fragment_boards_drawer)
private BoardsDrawerFragment _boardsDrawerFragment;