0

i have a problem here. I've ArrayList from the result of my parser class. then i wanna put that value (value from ArrayList) to TextView.

here is the work i've done till now. I create TextView on my main.xml

<TextView android:id="@+id/deskripsi" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> 

and here at my onCreate Method, i initialized the Text View

desk = (TextView)findViewById(R.id.deskripsi); 

and then i tried to parser the KML document from google map and at the Node Placemark i put its value to ArrayList, here my code

ArrayList<String> pathName = new ArrayList<String>(); Object[] objPlace; //Parser Node Placemark NodeList nlPlace = doc.getElementsByTagName("Placemark"); for(int p = 0; p < nlPlace.getLength(); p++){ Node rootPlace = nlPlace.item(p); NodeList itemPlace = rootPlace.getChildNodes(); for(int y = 0; y < itemPlace.getLength(); y++){ Node placeStringNode = itemPlace.item(y); NodeList place = placeStringNode.getChildNodes(); //valueName = nameList.item(0).getNodeValue().toString() + "+"; pathName.add(place.item(0).getNodeValue()); } } objPlace = pathName.toArray(); desk.setText(""); for (int j = 0; j < objPlace.length; j++){ desk.append("Deskripsi:\n" + objPlace[j].toString() + "\n"); } 

but when itried to run its to my emulator and real device, i get an error. here's my LogCat enter image description here

please help me, and sorry for my english >_<

2
  • which line in this code is 107 Commented May 19, 2012 at 12:25
  • Why do u put the arraylist to object[]? Commented May 19, 2012 at 12:27

5 Answers 5

10

You can do this instead; use pathName directly in the for loop...

desk.setText(""); for (int j = 0; j < pathName.size(); j++){ desk.append("Deskripsi:\n" + pathName.get(j) + "\n"); } 
Sign up to request clarification or add additional context in comments.

Comments

1

you can put the line

 objPlace[] = new Object[pathName.size()] 

before

objPlace = pathName.toArray(); 

and check output otherwise do this way

 desk.setText(""); for (int j = 0; j < pathName.size(); j++){ desk.append("Deskripsi:\n" + pathName.get(j) + "\n"); } 

Comments

0

You never initialize your array... objPlace[] is a null array.

You need to do something like:

objPlace[] = new Object[arraysizenumber] 

Comments

0

Ii is caused by NullPointerException, that means some needs parameters and you have passed a null value to it. Based on your code it might be around desk.setText("");. Try inserting a space or some value into it and run.

2 Comments

He got RunTimeException not NullPointerException
To quote the error posted above "Caused by: java.lang.NullPointerException"
0

Thanks my fren. im still not really well on using Object[]. then i used this code for solving my problem

String strPlace[] = (String[])pathName.toArray(new String[pathName.size()]); desk.setText(""); for (int j = 0; j < strPlace.length; j++){ desk.append("Deskripsi:\n" + strPlace[j] + "\n"); } 

Thanks for userSeven7s, flameaddict and khan for trying to help me. nice to know u all :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.