I found the problem. This is my edited code. The problem was the creation off the graph.
public class MainActivity extends Activity {
final static String TAG = MainActivity.class.getName();
private ObjectGraph mActivityGraph;
@Inject
Vehicle car;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActivityGraph = ObjectGraph.create(new ActivityModule());
mActivityGraph.inject(this);
Log.d(TAG,String.valueOf(car.getWheels().getInch()));
Log.d(TAG,car.getWheels().getBrand());
}
}
@Module(
injects =
{
Vehicle.class,
MainActivity.class,
Wheels.class
},
complete = false
)
public class ActivityModule{
@Provides Wheels provideWheels()
{
return new Wheels(4,"X12");
}
}
public class Vehicle {
@Inject
Wheels wheels;
private String type;
public String getType() {
return type;
}
public Wheels getWheels() {
return wheels;
}
}
public class Wheels {
private int inch;
private String brand;
@Inject
public Wheels(int inch, String brand) {
this.inch = inch;
this.brand = brand;
}
public int getInch() {
return inch;
}
public String getBrand() {
return brand;
}
}
The completes false is required otherwise dagger is going to complain about injectable constructors Integer and String.