gpt4 book ai didi

java - 将 fragment 更改为 RoboGuice fragment ?

转载 作者:行者123 更新时间:2023-12-01 15:21:05 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用 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
.

/编辑:

我认为我的问题是在进度条 fragment 中我正在这样做:

public static void setProgressBar(Activity parent, int visible) {
progressBar = (ProgressBar) parent.findViewById(R.id.progress_bar);
}

这可能不适用于 RoboGuice 注入(inject)?

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

最佳答案

为什么“progressBar”字段是静态的?

关于java - 将 fragment 更改为 RoboGuice fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10921512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com