アプリで RoboGuice を使用しようとしています。私の最初の試みは、単純な Fragment を RoboFragment に変更することです。しかし、アプリがコンパイルできなくなった後。ここで何が問題になる可能性がありますか?
class MyFragment extends RoboFragment {
@InjectView(R.id.progress_bar) private static ProgressBar progressBar;
}
結果:
E/AndroidRuntime(1237): java.lang.RuntimeException: Unable to start activity
ComponentInfo{path.to.MyApp}: android.view.InflateException: Binary XML file line #34:
Error inflating class fragment
.
/編集:
私の問題は、プログレスバーのフラグメント内でこれを行っていることだと思います:
public static void setProgressBar(Activity parent, int visible) {
progressBar = (ProgressBar) parent.findViewById(R.id.progress_bar);
}
これはおそらく RoboGuice インジェクションでは機能しないのでしょうか?
06-10 12:06:23.063: E/AndroidRuntime(676): FATAL EXCEPTION: main
06-10 12:06:23.063: E/AndroidRuntime(676): java.lang.RuntimeException: Unable to start activity ComponentInfo{MyActivity}: android.view.InflateException: Binary XML file line #42: Error inflating class fragment
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.os.Looper.loop(Looper.java:137)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-10 12:06:23.063: E/AndroidRuntime(676): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 12:06:23.063: E/AndroidRuntime(676): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 12:06:23.063: E/AndroidRuntime(676): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-10 12:06:23.063: E/AndroidRuntime(676): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-10 12:06:23.063: E/AndroidRuntime(676): at dalvik.system.NativeStart.main(Native Method)
06-10 12:06:23.063: E/AndroidRuntime(676): Caused by: android.view.InflateException: Binary XML file line #42: Error inflating class fragment
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-10 12:06:23.063: E/AndroidRuntime(676): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-10 12:06:23.063: E/AndroidRuntime(676): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
06-10 12:06:23.063: E/AndroidRuntime(676): at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
06-10 12:06:23.063: E/AndroidRuntime(676): at MyActivity.onCreate(MyActivity.java:109)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.Activity.performCreate(Activity.java:4465)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-10 12:06:23.063: E/AndroidRuntime(676): ... 11 more
06-10 12:06:23.063: E/AndroidRuntime(676): Caused by: java.lang.IllegalArgumentException: MyActivity@412f8b38 does not appear to be a RoboGuice context (instanceof RoboContext)
06-10 12:06:23.063: E/AndroidRuntime(676): at roboguice.inject.ContextScope.getScopedObjectMap(ContextScope.java:147)
06-10 12:06:23.063: E/AndroidRuntime(676): at roboguice.inject.ContextScope.enter(ContextScope.java:79)
06-10 12:06:23.063: E/AndroidRuntime(676): at roboguice.inject.ContextScopedRoboInjector.injectMembersWithoutViews(ContextScopedRoboInjector.java:241)
06-10 12:06:23.063: E/AndroidRuntime(676): at roboguice.fragment.RoboFragment.onCreate(RoboFragment.java:13)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:834)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:270)
06-10 12:06:23.063: E/AndroidRuntime(676): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
06-10 12:06:23.063: E/AndroidRuntime(676): ... 23 more