0

This is the error I'm getting in logcat:

01-12 09:41:43.885: W/dalvikvm(1474): Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/app/Items;

This is my Home.java class which is the main activity:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        homeTextViews = new TextView[Items.HomeItem.length];
}

And here is the Item.java class:

public class Items {
    public static final String[] HomeItem = new String[] { "string1", "string2", "string3" };


}

Upon starting the app I get the error said above as soon as it starts, the homeTextViews = new TextView[Items.HomeItem.length]; is the cause but I have no clue why. Anyone have any ideas?

I've also tried this but it still fails:

    Items items = new Items();
    homeTextViews = new TextView[items.HomeItem.length];

Items.HomeItem clearly isn't null, it's a static final so it shouldn't be null.

  • Have you tried to comment that line out and try if one of the other two causes the issue? – Fildor Jan 12 '16 at 10:02
  • @user How is it a duplicate when `Items.HomeItem' isn't `null`? It can't be null as it has a `final` modifier. – Error Dismissed Jan 12 '16 at 10:02
  • If you are sure Items.HomeItem isn't null, then maybe it isn't causing the issue. Which leaves you with the task to find out what *is* null. – Fildor Jan 12 '16 at 10:04
  • @Fildor What other two? If your talking about `super.onCreate(savedInstanceState);` & `setContentView(R.layout.home);` then no but they aren't the problem. – Error Dismissed Jan 12 '16 at 10:04
  • Are you 100% *sure*? – Fildor Jan 12 '16 at 10:05
  • @Fildor In the logcat it tells me the exact line number which is giving me the error and `homeTextViews = new TextView[Items.HomeItem.length];` is the only code on that line. – Error Dismissed Jan 12 '16 at 10:06
  • 3
    Is your `Items` class doing some other static initialization which might fail? Could you also post the entire stacktrace? – 0xDEADC0DE Jan 12 '16 at 10:11
  • @0xDEADC0DE Yeah... there was another in `Items`... which was the cause of the problem. Thanks that cleared that up. – Error Dismissed Jan 12 '16 at 10:15

0 Answers0