last day (23 days later) » 

7:09 PM
0
A: android getting NULL error on inject DI into class

ScottSBefore you can even use the object from GithubService class you need to do the following: myComponent= DaggerMyComponent.builder().computerModule(new ComputerModule()).build();//replace accordingly. In your case you will have to do something like: githubService = DaggerGithubApplicationCompo...

 
use githubService = GithubApplicationComponent.builder().nameofYourModule(new NameOfTheClass()).build); in GetLatestRepositories class ?
i pasted GithubService class into my post
 
No, in your application class.
 
i get this error: Cannot resolve method builder
 
It has to be in your application class. Within onCreate()
 
its DaggerGithubApplicationComponent, it seems your mean is not correct, because i get error
 
7:09 PM
Yes, you need to add prefix "Dagger": as follow githubService = DaggerGithubApplicationComponent.builder().nameofYourModule(‌​new NameOfTheClass()).build);
 
hi
see my last comment once you have replaced the lines I gave, now set that reference gitHubApplicationComponent = ".."
 
Thanks, but i think your answer is not correct, because i'm trying to use GihubService not DaggerGithubApplicationComponent
 
you need to first create a reference for the component
 
7:20 PM
and create a getter in the component to get that reference
then, on your class where you want to inject the object you do:
MyClass myClass;
 
i get error now
 
myClass = ((MyApp)getApplication()).getComponent.methodOfYourClass
that error is normal, the "DaggerGithubApplicationComponent" gets created once you have successfully injected the class
GithubApplicationComponent gitHubApplicationComponent; needs to be moved into the application's oncreate
 
it need to builder
 
see the examples above
 
7:28 PM
see example above I created, and just replace appropriately
you will declare and build your component on "Application" class
then you will just use the application's getter to obtain the object from your class.
as follow: "computer=((MyApp)getApplication()).getComponent().provideComputer();"
where provideComputer is a method from your component GithubApplicationComponent, whose return type is of type of the class you want to get the object from, i.e. GithubService
that is: "getGithubService()" you have already created it in your component class(GithubApplicationComponent"
 
can i send project for you sir? i cant resolve problem :(
 
first work on the application there only two lines to change.
and a getter method also on the application
Then you just have to call the get method from your application, because your application is global it can be seen by your class
so you call the getter method in your class to obtain reference of the component.
component handles all the classes you want to inject
 
I'm hanging now :( i read again your post, please let me to resolve that
 
you have that already
?
 
i'm not sure what i doing now
 
7:40 PM
just follow what I am saying
 
ok
i get this error: Error:(41, 36) error: cannot find symbol method getApplication()
githubService = ((Alachiq) getApplication()).getComponent().getGithubService();
 
go to your GetLatestRepositories class and move DaggersGithubApplicationComponent.Builder githubApplicationComponent into your application onCreate
first do as above.
let me know when done
 
show me your application class
 
its like with your application
 
7:45 PM
show me
 
    component = DaggerGithubApplicationComponent.builder()
            .contextModule(new ContextModule(this))
            .build();
public GithubApplicationComponent getComponent() {
    return component;
}
 
what is the name of your application?
 
Alachiq
 
it will be easier if i see it
have you defined the application in your manifest?
you must have something like "<application
android:allowBackup="true"
android:name=".MyApp" </application>
replace .MyApp with the name of your app, Alachiq
 
yes i have this line in manifets
<application
    android:name=".CoreAlachiq.Alachiq"
 
7:49 PM
your activity must extend "AppCompatActivity"
 
yes, its correct
 
you are extending Job
 
BaseActivity extends from AppCompatActivity
Job is other class which i want to inject GithubService into that
please let me, i'm back as soon as possible, My laptop dont have charge :(
 
?
 
please let me to send project for you
 
7:53 PM
you need to extends AppCompatActivity in the class where you want to use application
or extends BaseActivity
build it faster by going to "Settings"> "Build, Execution, Deployment"> "Gradle"> uncheck "Offline work"
I mean checking it not unchecking it
 

  last day (23 days later) »