我试图在Android上使用Dagger 2.我以前有它工作,我有一个appModule注入依赖于应用程序中的特定类.我的问题是我得到了错误
Error:(14, 55) error: cannot find symbol class DaggerAppComponent
Run Code Online (Sandbox Code Playgroud)
试图导入.这是一个自动生成的类
下面是我的build.gradle文件中的Dagger特定依赖项
compile 'com.google.dagger:dagger-compiler:2.0.2'
compile 'com.google.dagger:dagger:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
Run Code Online (Sandbox Code Playgroud)
我曾多次尝试清理和重建应用程序,但课程不会产生.我也试过用
compile 'org.glassfish:javax.annotation:10.0-b28'
Run Code Online (Sandbox Code Playgroud)
对于我的注释,但我仍然没有运气?如果有人可以帮助我id欣赏.很难确切地看到我目前到底发生了什么?谢谢
编辑:这是以前工作的组件代码,我只是添加了1个额外的类注入?
@Singleton
@Component(modules = AppModule.class)
public interface AppComponent {
void inject(RegHelper reghelper);
void inject(headerFooterRecViewAdapter headadapter);
void inject(SectionListExampleActivity seclistactivity);
}
Run Code Online (Sandbox Code Playgroud) 我试图在android上的robolectric进行测试.基本上我有一个将序列化对象写入文件的类.我将一个上下文传递给构造函数并使用它来调用该方法getFilesDir()
new File(context.getFilesDir(), filename);
Run Code Online (Sandbox Code Playgroud)
我在RuntimeEnvironment.application测试时作为上下文传入,但是当我调用下面的方法测试文件是否存在时,我得到一个断言失败.
@Override
public boolean fileExists() {
return context.getFileStreamPath(filename).exists();
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有另一种方法来解决这个问题,并使用测试上下文来创建文件.提前致谢!
这是我运行的简单测试
@Test
public void testFileCreated()
{
objmodelroom.createFile();
assertTrue(objmodelroom.fileExists());
}
Run Code Online (Sandbox Code Playgroud)
我像这样创建文件
public void createFile()
{
this.objectfile = new File(context.getFilesDir(), filename);
objectfile.setReadable(true);
objectfile.setWritable(true);
}
Run Code Online (Sandbox Code Playgroud) 我正在编写代码以从我的Android客户端访问我的Web服务.在那一刻我正在使用改装为各种调用返回一个可观察的类型.此刻我有4个这些(如下所示)
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<List<EntryItem>> getNewsAndComments(@Path("pathto") String pathto, @FieldMap Map<String, String> fieldnames);
/**
* adding a comment. returns observable
* with message entity type
*
* @param pathto
* @param fieldnames
* @return
*/
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<message> postComment(@Path("pathto") String pathto, @FieldMap Map<String, String> fieldnames);
@FormUrlEncoded
@POST("/{pathto}")
Call<message> regDevice(@Path("pathto") String pathto ,@FieldMap Map<String, String> fieldnames);
/**
* return a Map of canteen menu items!
*
* @param path
* @param fielditems
* @return
*/
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<Map<String, ArrayList<CantItem>>> getCanteenItems(@Path("path") String path, @FieldMap …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关处理常见手势的android文档.我GestureDetectorCompat在我的主要活动中创建了一个实例,但这个特定的类似乎在活动中没有被识别.我尝试将这一行添加到我build.gradle的包中的依赖项中,但我仍然没有任何乐趣.
compile "com.android.support:support-v4:13.0.+"
Run Code Online (Sandbox Code Playgroud)
我不太清楚这里发生了什么,因为当我在依赖项中添加这一行时,我会想到使用的选项GestureDetectorcompat可用吗?另外我的min SDK设置为15,我的目标SDK是19.我想知道这是否阻止我使用GestureDetectorCompat?您可以提供任何澄清,非常感谢.
我应该把我的改装调用放在Android服务类中吗?对于我的应用程序,我在某些类中调用内部改造,例如下面
Call<ArrayList<CantItem>> mycall = retrofitcalls.getCanteenItems("url.php", urldatamap);
mycall.enqueue(new Callback<ArrayList<CantItem>>() {
@Override
public void onResponse(Response<ArrayList<CantItem>> response, Retrofit retrofit) {
int code = response.code();
Log.d("code ", String.valueOf(code));
if (code == 200 || code == 201) {
ArrayList<CantItem> cantitems = response.body();
Log.d("retrieved", "returned items");
savedToSharedPrefs(createString(cantitems));
cantmap = createMap(cantitems);
presenter.updateView(cantmap);
}
}
@Override
public void onFailure(Throwable t) {
Log.d("couldnt retrieve", "failure");
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道我应该把这个电话放在Android服务类中吗?因为我的改装调用无论如何都是异步运行的?我见过的每个教程似乎都在课程或活动中运行它.我没见过有人使用过服务.我不是100%肯定目前最好的方法.谢谢