1
votes

I want to show the items in my list to textviews.

The wordslist.java is

public class WordsList {

List<String> set1 = new ArrayList<>(Arrays.asList("sane", "said",
        "dean", "ideas", "deans", "anise", "naiades", "sand", "aide",
        "dais", "saned", "aside", "sedan", "idea", "aids", "ands",
        "naiad", "aides", "naiads"));
// 19 words

List<String> set2 = new ArrayList<>(Arrays.asList("doer", "lord",
        "rode", "role", "drool", "older", "flooder", "odor", "lore",
        "rood", "fore", "rodeo", "folder", "floored", "door", "roof",
        "redo", "ford", "floor", "roofed"));
// 20 words
List<String> set3 = new ArrayList<>(Arrays.asList("mead", "dale",
        "lead", "dual", "lamed", "mauled", "medulla", "lade", "male",
        "alum", "maul", "mall", "ladle", "malled", "dame", "made", "lame",
        "laud", "meal", "medal", "allude"));
// 21 words

Actually these are the answers of the puzzle, there about 25 puzzles(from set1 to set 25)

When the user clicks give Up. it goes to gameover activity in that activity i have button ' show missed words' ,now when this button is pressed , i want to show the items in the corresponding list.

for showing the words i created a xml layout with some textviews.

LinearLayout myLayout;
    myLayout = (LinearLayout) findViewById(R.id.tvLayout);
myTextViewList = new ArrayList<>();

for (int i = 0; i < myLayout.getChildCount(); i++)
if (myLayout.getChildAt(i) instanceof TextView)
myTextViewList.add((TextView) myLayout.getChildAt(i));
and when to set text
WordsList w = new WordsList();
TextView tv = myTextViewList.get(counter);
tv.setText(w.set1);

Here is my logcat

 01-28 20:29:42.105  11122-11122/rpa.screening.spellathon E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: rpa.screening.spellathon, PID: 11122
    java.lang.NullPointerException
            at rpa.screening.spellathon.GameOver_Screen$2.onClick(GameOver_Screen.java:44)
            at android.view.View.performClick(View.java:4487)
            at android.view.View$PerformClick.run(View.java:18746)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
            at dalvik.system.NativeStart.main(Native Method)

EDIT 2 : Gameover_screen

missedWords.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent iin = getIntent();
            Bundle b = iin.getExtras();


            if (b != null) {

                String passed_score = (String) b.get("score");
                displayScore.setText(passed_score);
                int passed_set = (int) b.get("set"); // line 44
                String s = Integer.valueOf(passed_set).toString();


                Intent ii = new Intent(GameOver_Screen.this, MissedWords.class);
                ii.putExtra("sEt", s);
                startActivity(ii);
            }
        }
    });
1
Its like a Spellathon type app.Mann
Please be clear what do you want to ask !Abhinav Arora
tell us where Your problem is. What You´ve tried and what doesn´t work...Opiatefuchs
i want to show the items in the list in textviewsMann
Why not using ListView or RecyclerViewsockeqwe

1 Answers

1
votes

SOLVED MY QUESTION.

The actual problem is here,

tv.setText(w.set1);

but when i changed it to,

String set1 = w.set1.get(i);
tv.setText(set1);

the problem solved.