aspose file tools*
The moose likes Beginning Java and the fly likes I am getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I am getting "void type not allowed here" error" Watch "I am getting "void type not allowed here" error" New topic
Author

I am getting "void type not allowed here" error

Deepu Dangol
Greenhorn

Joined: Nov 15, 2009
Posts: 3
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

Joined: Mar 09, 2009
Posts: 600
'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

Joined: Nov 15, 2009
Posts: 3
What shoiuld I do then?
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Well, what do you think you should do?

John.
Deepu Dangol
Greenhorn

Joined: Nov 15, 2009
Posts: 3
I changed the void to String and returned as return markLength4(list) but didn't get the result.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
 
subject: I am getting "void type not allowed here" error