This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am getting "void type not allowed here" error

 
Deepu Dangol
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.ArrayList;

public class TestArrayList
{
public static void main(String[ ] args)
{
ArrayList list = new ArrayList( );
list.add("this");
list.add("is");
list.add("lots");
list.add("of");
list.add("fun");
list.add("for");
list.add("every");
list.add("java");
list.add("programmer");
System.out.println(list.toString());

}

public static void markLength4(ArrayList<String> list)
{
int index = 0;
while(index < list.size())
{
String next = (String)list.get(index);
if(next.length( ) == 4)
{
list.add(index, "****");
index = index + 1;
}
else
index = index + 1;
}

for(index = 0; index < list.size( ) ; index++)
{
System.out.println(list.get(index));

}
System.out.println(markLength4(list));
}
}
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'Dmx Dangol':

You're trying to return a value from a method marked as void. You can't do that.

Also, just as a friendly suggestion, you need to change your username to your real name. That is one of the rules of this forum, and the moderators will enforce it.

John.
 
Deepu Dangol
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What shoiuld I do then?
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what do you think you should do?

John.
 
Deepu Dangol
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the void to String and returned as return markLength4(list) but didn't get the result.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A method has a return type; it must return something which matches that type.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic