Browsing 7239 questions and answers with Jon Skeet

Cookie gives an error with date

I followed a tutorial on youtube regarding creating a cookie. I typed in the correct code, but I get an error in the line with: cookie = new Cookie("test_cookie",...
Jon Skeet
people
quotationmark

You're importing java.sql.Date - which doesn't have a parameterless constructor. You meant java.util.Date, which does. However, there's no need to create a Date object at all in order to get the current time in... more 2/28/2014 9:29:22 AM

people

Creating 0.000.. with certain decimals

I am trying to create the number 0.00000.... with as many '0' as the user input wants. What is wrong with my code below? int n; double dec = 0.0; in = new...
Jon Skeet
people
quotationmark

You're expecting double to retain the number of decimal digits - it doesn't do that. The value is always normalized. The double type is all about the magnitude of a number, not a particular decimal representation. It's suitable for... more 2/28/2014 9:10:37 AM

people

How to change Cursor position in Console?

I wanted to use Console.ReadLine(); in the previous line and make it display like that: HeresomeText>(input) Not like HeresomeText> (input) Is it possible to do?
Jon Skeet
people
quotationmark

Absolutely - look at the various members of the System.Console class. In particular, you want the SetCursorPosition method, but if you're writing a "fancy" console app you should think about the members for using colours etc too. more 2/28/2014 8:13:55 AM

people

Why do the source folders in package explorer appear in not alphabetical order

I'm looking at a few projects in Eclipse's Package Explorer. I expect to see the items listed in this order: My Awesome Project + src/main/java + src/test/java +...
Jon Skeet
people
quotationmark

That's just how your build path is configured. Right-click on the project, select Build Path / Configure Build Path, then under "Order and Export" you can move the source folders etc up and down. more 2/28/2014 8:04:32 AM

people

Read closes the whole program regardless of other Reads.

So I'm trying to make a program that allows users to insert values for length and width and then another method is called to calculate the area and perimeter. Howevever, I can't...
Jon Skeet
people
quotationmark

Console.Read only reads a single character - but it will wait until you've hit enter in order to do so. So what's happening is that you're typing something then hitting enter, then Console.Read will return, then you'll try to read another... more 2/27/2014 11:43:53 PM

people

LINQ to XML getting XElement values

I am having an issue with getting some values back from LINQ to XML query. I have got the XML from a SOAP web service and passed this through and parsed this into an XDocument to...
Jon Skeet
people
quotationmark

This is what's causing you the headache: xmlns="http://webservices.whitespacews.com/" That's setting the default namespace for the element and its descendants - so you need to look for elements with a local name of Collections and that... more 2/27/2014 11:34:41 PM

people

What is the purpose of the using statement?

On the basis of what is written on this web page, and if I understand correctly, the using statement works like a try/finally, so I might mistakenly expect that if an exception...
Jon Skeet
people
quotationmark

if I understand correctly, the using statement works like a try/finally Correct. so I would expect that if an exception occurs in a using statement, it should not crash the program. Incorrect. Neither try/finally nor using... more 2/27/2014 11:28:45 PM

people

Object[] array to String[] using Serialization

The readObject() method of the ObjectInputStream returns Object and that needs to be casted to appropriate type. what if I serialize an array of String, do I get array of Objects...
Jon Skeet
people
quotationmark

Array variance allows you to treat a String[] as an Object[] with no problems, and you can then cast back with no problems: Object[] x = new String[] { "x", "y", "z" }; System.out.println(x.getClass()); // Prints class... more 2/27/2014 11:00:04 PM

people

What is a less Kludgy way to Conditionally Prepend a "0" to dateTime Elements?

I want my string YearMonthDayHourMinuteSecondMillisecond to be of this format ("0" prepended where necessary): 20140227142807 ...but this: string YearMonthDayHourMinuteSecond...
Jon Skeet
people
quotationmark

Don't use string.Format at all - use DateTime.ToString(): string text = dt.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); Or to just go down to seconds: string text = dt.ToString("yyyyMMddHHmmss",... more 2/27/2014 10:39:36 PM

people

NoClassDefFoundError thrown even when required class is present in classpath

Trying to run jar program and getting class not found error. As shown in the figure, I have packaged all my dependent jar under lib folder and packaged it inside jar file....
Jon Skeet
people
quotationmark

I believe the problem is the format of your Class-Path entry. As per the tutorial: You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the... more 2/27/2014 9:29:21 PM

people