Skip to content Skip to sidebar Skip to footer

Android Annotations With Tabs + Viewpager Giving Nullpointer Exception

I created a simple android project in Android Studio using navigation type Tabs + Viewpager. The code compiles and runs OK. But after i included android annotations, i get a null p

Solution 1:

If you add a layout to the class declaration, you shouldn't reference views in onCreate. Instead, you should inject the views with @ViewById and use them in a separate method with @AfterViews. More on that here:

https://github.com/excilys/androidannotations/wiki/Injecting-Views

Solution 2:

Yes exactly agree with above answer there are 2 ways to use the views

1.) if you use ... @EActivity(R.layout.activity_main) .... you have to use @AfterViews ... and

2.) if you want to use @Override protected void onCreate(Bundle savedInstanceState).. you have to use setContentView(R.layout.activity_main);

-Above are the combinations which should be used together always for proper code usage

_Thanks !~!

Post a Comment for "Android Annotations With Tabs + Viewpager Giving Nullpointer Exception"