0

I am making an android application, which creates a dynamic interface, according to a string read from your preferences:

ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);

    TableLayout tl = new TableLayout(this);
    TableRow[] tr = null;

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String Favs = SP.getString("Favs", "None");
    String[] Genveje;
    if (!Favs.equals("None"))
    {
        Genveje = Favs.split(";");
        tr = new TableRow[Genveje.length];
        for (int i = 0; i < Genveje.length; i++)
        {
            String BtnName = Genveje[i].split("@")[0];
            String BtnPath = Genveje[i].split("@")[1];
            Button btn = new Button(this);

            btn.setText(BtnName);
            btn.setTag(BtnPath);
            btn.setOnClickListener(this);
            btn.setOnLongClickListener(this);


            tr[i].addView(btn);

                    .........
        }

The problem is: when i try to do ANYTHING with tr[i] i get a NullPointerException, and i have no clue why.

Anyone with a suggestion?

1 Answer 1

2
tr[i]=new TableRow(this);
tr[i].addView(btn);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.