Karumi / Rosie

Rosie is an Android framework to create applications following the principles of Clean Architecture.
Other
1.82k stars 156 forks source link

Extending RosieApplication #59

Closed sargunv closed 8 years ago

sargunv commented 8 years ago

The documentation states "If you do not want to use Dependency Injection in your project, you do not need to extend from RosieApplication", but I get a ClassCastException when I don't extend RosieApplication:

Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.karumi.rosie.application.RosieApplication
   at com.karumi.rosie.view.RosieAppCompatActivity.injectActivityModules(RosieAppCompatActivity.java:133)
   at com.karumi.rosie.view.RosieAppCompatActivity.onCreate(RosieAppCompatActivity.java:46)
   at me.sargunvohra.android.diningcourts.MainActivity.onCreate(MainActivity.kt:17)
   at android.app.Activity.performCreate(Activity.java:6876)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
   at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:158) 
   at android.app.ActivityThread.main(ActivityThread.java:7229) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
matbrandao commented 8 years ago

+1

Serchinastico commented 8 years ago

Yup, if we want to provide that functionality properly we should be doing a runtime type check instead of forcing the downcast right away.

chuchivic commented 8 years ago

If you import the project as a module, you can comment a couple of lines and works perfectly:

RosieActivity.java

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //TODO comentado /if (shouldInitializeActivityScopeGraph()) { injectActivityModules(); }/ int layoutId = getLayoutId(); setContentView(layoutId); ButterKnife.bind(this); onPreparePresenter(); //TODO comentado //presenterLifeCycleLinker.initializeLifeCycle(this, this); }

RosieApplication.java:

@Override public void onCreate() { super.onCreate(); /initGraph(); injectApplication();/ }

pedrovgs commented 8 years ago

@sargunster we have just released a new version with the fix. Thanks!