0

I brought some interesting problem.

It is about Nullpointer exception and it is only occur at specific phone, Samsung Galaxy Note3-5.1.0. Since I didn't checked all the other phones, however, running on genymotion-samasung-galaxyS5-4.4.4 was fine.

The code is following.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
    final LinearLayout btn_search = (LinearLayout) findViewById(R.id.searchBtn);
    final LinearLayout btn_mypage = (LinearLayout) findViewById(R.id.mypageBtn);
    final LinearLayout btn_map = (LinearLayout) findViewById(R.id.mapBtn);
    Log.d("NULLPOINTER",": " + btn_search + " " + btn_map + " " + btn_mypage);

}

Then, the log is like,

D/NULLPOINTER: : null android.widget.LinearLayout{2ae0be1a V.E..... ......I. 0,0-0,0 #7f0e007d app:id/mapBtn} android.widget.LinearLayout{1db90d4b V.E...C. ......I. 0,0-0,0 #7f0e007e app:id/mypageBtn}

I checked all the R.id.*** and layout and since they are implemented in same way, I don't know what is the problem. Strangely, only the first one, which was lastly added is always null. However, on the other phones I can get the object well.

Do you know any idea?

Mark Yoon
  • 330
  • 4
  • 17
  • Add the stacktrace - also what do your layout folders look like? Do you have one or one for each screen density? – apmartin1991 Nov 02 '15 at 17:20
  • @apmartin1991 yeah, you are totally right, my team add the different version of layout but, we don't fix the specific id name. so all ID has to be fixed. – Mark Yoon Nov 02 '15 at 18:02
  • Shame I was unable to answer this properly and that for some reason it was closed (no idea why!) It is clearly not a duplicate... Glad I could help though – apmartin1991 Nov 02 '15 at 21:58

0 Answers0