Browsing 7239 questions and answers with Jon Skeet

port 8080 is already in use and no process using 8080 has been listed

I am trying to start Tomcat from Eclipse, but a problem occured: Port 8080 required by Tomcat v6.0 Server at localhost is already in use. The server may already be running...
Jon Skeet
people
quotationmark

PID is the process ID - not the port number. You need to look for an entry with ":8080" at the end of the address/port part (the second column). Then you can look at the PID and use Task Manager to work out which process is involved... or... more 11/13/2013 10:34:55 PM

people

Java: Unable to read image file

I am trying to load an png using this code: BufferedImage image = ImageIO.read(new File(getClass().getResource(fileName).toString()); The file exists, in the directory exists,...
Jon Skeet
people
quotationmark

I would avoid trying to read using a File at all - just use the URL returned by getResource: BufferedImage image = ImageIO.read(getClass().getResource(fileName)); Aside from anything else, that will still work when the resource is in a... more 11/13/2013 10:15:41 PM

people

Unobserved task exceptions in .NET4

According to some articles and blogs a code like the following one should lead to an exception in .NET 4 static void Main(string[] args) { Task.Factory.StartNew(()...
Jon Skeet
people
quotationmark

My guess is that you're actually running on .NET 4.5. Bear in mind that .NET 4.5 is effectively installed over the top of .NET 4. Even if your application is targeted at .NET 4, if the user has installed .NET 4.5 you'll get the new... more 11/13/2013 5:31:14 PM

people

What happens to lines of Java .properties file which don't match the key value pattern

I have a java library which I need to treat as a black box and which requires a properties file to exist on the class path. However, I have a system in place which only allows the...
Jon Skeet
people
quotationmark

You end up with an empty string value for the keys "<dummy>" and "</dummy>". You can show this easily: import java.io.*; import java.util.*; public class Test { public static void main(String[] args) throws IOException { ... more 11/13/2013 5:00:00 PM

people

Good practice throw an exception to satisfy a function return

Built a custom IDataReader which goes looking in XML for values that match particular element names and, if found, returns the values. The GetValue function - which has to return...
Jon Skeet
people
quotationmark

Well unless you really need the catch block, you don't need to introduce try/catch/finally. You can just add a throw statement at the end of your initial method. Along the way, I'd start using FirstOrDefault(), follow normal C# naming... more 11/13/2013 2:56:48 PM

people

Function with IFormattable parameter won't accept a String

I have a function where I processed a string input. public string Foo(string text) { // do stuff with text and // return processed string } I was...
Jon Skeet
people
quotationmark

Simply put, System.String doesn't implement IFormattable. If the documentation isn't enough for you: object x = "a string"; Console.WriteLine(x is IFormattable); // False Given that ToString() is declared on object, why not just... more 11/12/2013 9:01:54 PM

people

ArrayList Contents Modifying Unexpectedly

Pulled an interview question out of an old java certification book I have from back in the day. Don't want to really want to get into whether of not it is a good interview...
Jon Skeet
people
quotationmark

Since the clear of list2 altered the contents of list1 Yes. Because ArrayList.subList is following the documented behaviour of List.subList: Returns a view of the portion of this list between the specified fromIndex, inclusive,... more 11/12/2013 6:02:19 PM

people

Why can't java find my class?

I have a class that compiles without error. The class has a main method. But when I try to run it on ubuntu linux from the classes' directory I get a class not found error. I am...
Jon Skeet
people
quotationmark

The original problem was that your class was in a package, but you were trying to load it as if it weren't in a package. You'd normally organize your source code to match your package hierarchy, then from the root of the hierarchy, you'd... more 11/12/2013 4:37:24 PM

people

Reading Specific Set Of XML Nodes via LINQ

I have an XML file that looks like this... <return> <availableOptions> <premiums> <item> <productCode>Poroduct Code...
Jon Skeet
people
quotationmark

How can i have the LINQ just focus on the first <item> instead? I assume you don't just want the very first <item>, but each top-level <item>. Just change Descendants("item") to Elements("item"). That way it will... more 11/12/2013 3:59:34 PM

people

Increment calendar with day

I have a strange problem when i increment days in Calendar. I want to loop over every day of a year. This is my code Date d = null; SimpleDateFormat textFormat = new...
Jon Skeet
people
quotationmark

This is the problem: "-"+cal.get(Calendar.MONTH)+1 That's actually performing string concatenation - it's effectively ("-" + cal.get(Calendar.MONTH)) + 1 So when cal.get(Calendar.MONTH) returns 1, that's effectively: ("-" + 1) + 1... more 11/12/2013 9:02:32 AM

people