我是RoboGuice的新手,我正在尝试设置我的活动来使用DI。但是,当我尝试使用它时没有任何反应。在我调用“super.onCreate(savedInstanceState);”后,我只得到一个空白的黑色窗口,没有内容,也没有记录在我的Activity.onCreate()方法中。当我配置RoboGuice时没有任何反应
参见这些2个片段的代码:
public class ClikClokActivity extends RoboActivity{
@Inject
private TileAdapter tileAdapter;
@Inject
private GameLogicService gameLogicService;
@Inject
private GridOperationQueue gridOperationQueue;
private GridView gridView;
@Inject
private Handler handler;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.v(this.getClass().toString(), "Entering onCreate");
super.onCreate(savedInstanceState);
Log.v(this.getClass().toString(), "Never logs this with RoboGuice");
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridview);
gridView.setNumColumns(Constants.GRID_WIDTH);
gridView.setAdapter(tileAdapter);
Log.v(this.getClass().toString(), "GridView initialized");
gridOperationQueue.start();
Log.v(this.getClass().toString(), "Completed onCreate");
}
和
public class ClikClokApplication extends RoboApplication{
@Override
protected void addApplicationModules(List<Module> modules) {
modules.add(new ClikClokModule());
}
}
和
公共类ClikClokModule延伸AbstractAndroidModule {
@Override
protected void configure() {
}
}
和
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.clikclok"
android:versionCode="1"
android:versionName="1.0">
<application android:name="com.clikclok.ClikClokApplication" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ClikClokActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
如果你看一下上面的代码,我从来没有第二个记录。但是,如果我是从Activity扩展而来,并从清单中删除android:name =“com.clikclok.ClikClokApplication”属性,那么我确实会得到第二个日志记录(尽管NullPointers失败,因为没有执行初始化)。
那么super.onCreate(savedInstanceState)中可能发生了什么;这是导致我的应用程序不工作?
由于从上面
更新:
我花了相当多的时间来调查这一点,并使用Eclipse的调试器现在可以看到我的代码似乎内RoboGuice挂起。
下面的代码是从InjectorImpl类:
public void injectMembers(Object instance) {
// Reaches here but...
MembersInjector membersInjector = getMembersInjector(instance.getClass());
// ....this comment is never reached
membersInjector.injectMembers(instance);
}
所以我用我的调试器挖成吉斯3.0码,进入FailableCache类:
public V get(K key, Errors errors) throws ErrorsException {
// Reaches here....
Object resultOrError = delegate.get(key);
// ...but not here
if (resultOrError instanceof Errors) {
errors.merge((Errors) resultOrError);
throw errors.toException();
} else {
@SuppressWarnings("unchecked") // create returned a non-error result, so this is safe
V result = (V) resultOrError;
return result;
}
}
这是怎么回事,它只是从ma中检索密钥时挂起P +我对代码不够熟悉,对于疑难解答相当困惑。 任何意见表示赞赏。
似乎它不能登录第二行的唯一方法是如果你的应用程序在日志1和日志2之间崩溃。日志中是否有任何错误? – emmby
绝对没有在日志中。这就是为什么我完全迷失在这里 – DJ180
此外,请确保你根据你的roboguice版本做了一切。在roboguice2.0中,您不需要(不能)使用RoboApplication类。相反,您需要在res/values文件夹中创建一个roboguice.xml文件。请参阅升级说明:http://code.google.com/p/roboguice/wiki/UpgradingTo20 – Entreco