Cannot enter null value in class

I have a fragment that I want to reuse. Its functionality is the same, only layout changes

I use roboguice to inject id views into variables

I added this view, for example:

@Nullable
@InjectView(R.id.edtEventLocationAddress)
private EditText edtEventLocationAddress;

this view may or may not be present in this layout i, presented in the onCreateView method

that's why i put on it @Nullable

however, when I launch the application, with a layout that does not have this representation, I get

java.lang.NullPointerException: Can't inject null value into class 
com.myapp.CreateEventPageFragment.edtEventLocationAddress when field is not @Nullable

What do I need to do so that roboguice allows me to reuse fragments and only change their presentation?

+4
source share
3 answers

, - .

, android.support.annotation.Nullable @Retention(RetentionPolicy.CLASS) ( RetentionPolicy.SOURCE). , @Nullable, RoboGuice, . . :

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD, ElementType.METHOD,
    ElementType.PARAMETER,
    ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {}
+3

javax.annotation.Nullable android.support.annotation.Nullable, (. Michael.F).

0

( ) , XML Inject, null, .

0

All Articles