我有一个小场景,我有以下结构,我试图在 baseActivity Fragment 中注入(inject) fragment 管理器,但由于某种原因我运气不佳:(
@Singleton
@Component(modules = { AppModule.class,
ActivityModule.class,
AndroidSupportInjectionModule.class })
public interface AppComponent extends AndroidInjector<App> {
@Override
void inject(App application);
@Component.Builder interface Builder {
@BindsInstance
AppComponent.Builder application(App application);
AppComponent build();
}
}
ActivityModule.class
@PerActivity
@ContributesAndroidInjector(modules = BaseActivityModule.class)
abstract BaseActivity baseActivity();
BaseActivityModule.class
static final String ACTIVITY_FRAGMENT_MANAGER = "ACTIVITY_FRAGMENT_MANAGER";
@PerActivity
@Named(ACTIVITY_FRAGMENT_MANAGER)
@Provides
static FragmentManager activityFragmentManager(BaseActivity activity) {
return activity.getSupportFragmentManager();
}
BaseAcitivity.class
public abstract class BaseActivity extends DaggerAppCompatActivity {
@Named(ACTIVITY_FRAGMENT_MANAGER)
@Inject
FragmentManager fragmentManager;
}
因此,即使我在 BaseActivityModule.class Dagger 中提供了我的 fragment 管理器,也会抛出以下错误。我什至尝试只使用 Activity 而不是 BaseActivity 作为我在 BaseActivityModule 中的输入参数。即便如此,我还是陷入了同样的问题。不确定我到底搞砸了什么。所以任何帮助表示赞赏。提前致谢:)
Error:(17, 8) error: [dagger.android.AndroidInjector.inject(T)] @javax.inject.Named("ACTIVITY_FRAGMENT_MANAGER") android.support.v4.app.FragmentManager cannot be provided without an @Provides- or @Produces-annotated method.
@javax.inject.Named("ACTIVITY_FRAGMENT_MANAGER") android.support.v4.app.FragmentManager is injected at
com.abc.views.base.BaseActivity.fragmentManager
com.abc.views.def.ABCActivity is injected at
dagger.android.AndroidInjector.inject(arg0)
A binding with matching key exists in component: om.abc.views.base.BaseActivity_BaseActivity.BaseActivitySubcomponent
最佳答案
“组件中存在具有匹配键的绑定(bind)”意味着您在整个对象图中的某处绑定(bind)了一个依赖项,但无法从需要注入(inject)它的子组件到达它。
这是 javadoc :
Utility code that looks for bindings matching a key in all subcomponents in a binding graph so that a user is advised that a binding exists elsewhere when it is not found in the current subgraph. If a binding matching a key exists in a sub- or sibling component, that is often what the user actually wants to use.
例如,假设您有两个 Activity,ActivityA 和 ActivityB。您使用 @ContributesAndroidInjector 生成子组件并在 ActivityA 模块中绑定(bind) Foo 而不是 ActivityB 模块。如果您使用 @Inject Foo foo 请求在 ActivityB 中注入(inject) Foo,您将收到该错误消息。
在像 BaseActivity 这样的基类上使用 @ContributesAndroidInjector 形成子组件在这里可能不是一个好的方法。就像来自 David Medenjak 的评论一样, 基类的子组件将被忽略,具体类的子组件将对 ABCActivity 执行注入(inject)。
现在,您可以通过在 ABCActivity 的子组件中绑定(bind) FragmentManager 来修复错误:
@PerActivity
@ContributesAndroidInjector(modules = BaseActivityModule.class)
abstract ABCActivity ABCActivity();
关于android - Dagger 2.11 - 组件中存在具有匹配键的绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47106818/
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
我的模型有defself.empty_building//stuffend我怎样才能对这个现有的进行rspec?,已经尝试过:describe"empty_building"dosubject{Building.new}it{shouldrespond_to:empty_building}endbutgetting:Failure/Error:it{shouldrespond_to:empty_building}expected#torespondto:empty_building 最佳答案 你有一个类方法self.empty_bu
运行bundleinstall后出现此错误:Gem::Package::FormatError:nometadatafoundin/Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gemAnerroroccurredwhileinstallinglibv8(3.11.8.13),andBundlercannotcontinue.Makesurethat`geminstalllibv8-v'3.11.8.13'`succeedsbeforebundling.我试试gemin
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
有几种方法:first_or_create_by、find_or_create_by等,它们的工作原理是:与数据库对话以尝试找到我们想要的东西如果我们找不到,就自己做保存到数据库显然,并发调用这些方法可能会使两个线程都找不到它们想要的东西,并且在第3步中一个线程会意外失败。似乎更好的解决方案是,创建或查找即:提前在您的数据库中创建合理的唯一性约束。如果你想保存一些东西,就保存它如果有效,那就太好了。如果它因为RecordNotUnique异常而无法工作,它已经存在,太好了,加载它那么在什么情况下我想使用Rails内置的东西而不是我自己的(看起来更可靠)create_or_find?
我正在运行Ubuntu11.10并像这样安装Ruby1.9:$sudoapt-getinstallruby1.9rubygems一切都运行良好,但ri似乎有空文档。ri告诉我文档是空的,我必须安装它们。我执行此操作是因为我读到它会有所帮助:$rdoc--all--ri现在,当我尝试打开任何文档时:$riArrayNothingknownaboutArray我搜索的其他所有内容都是一样的。 最佳答案 这个呢?apt-getinstallri1.8编辑或者试试这个:(非rvm)geminstallrdocrdoc-datardoc-da
是否可以在不实际下载文件的情况下检查文件是否存在?我有这么大的(~40mb)文件,例如:http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm这与ruby不严格相关,但如果发件人可以设置内容长度就好了。RestClient.get"http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm",headers:{"Content-Length"=>100} 最佳答案
当且仅当模型存在时,我才尝试更新模型的值。如果没有,我什么都不做。搜索似乎只返回更新或创建问题/答案,但我不想创建。我知道我可以用一个简单的方法来做到这一点:found=Model.find_by_id(id)iffoundupdatestuffend但是,我觉得有一种方法可以在一次调用中完成此操作,而无需分配任何临时本地值或执行if。如果记录不存在,我该如何编写一个Rails调用来更新记录而不出现嘈杂错误?最新的Rails3.x 最佳答案 您可以使用try在对find_by_id或where的结果调用update_attribut
类似的东西:defdomain_exists?(domain)#performcheck#returntrue|falseendputs"valid!"ifdomain_exists?("example.com") 最佳答案 require'socket'defdomain_exists?(domain)beginSocket.gethostbyname(domain)rescueSocketErrorreturnfalseendtrueend 关于ruby-如何使用Ruby检查域是否存