Browsing 7239 questions and answers with Jon Skeet

Is JAVA necessary for android development?

I know C, C++, javascript and most web languages like php,ruby etc.. and web frameworks. I am a little bit aware of eclipse ide for javascript and c/c++ developers, so are they...
Jon Skeet
people
quotationmark

Java is the standard way of writing Android apps, but it's not strictly necessary. For example, there's also Xamarin.Android which lets you write Android apps in C# - although it will still fire up a Dalvik VM behind the scenes, as the... more 1/3/2014 8:20:40 AM

people

Cannot parse xml from Yahoo! Fantasy Sports with c#

I did some searching around the web and could not find the cause of my problem so I apologize if that has already been asked in another form I just did not understand. My problem...
Jon Skeet
people
quotationmark

This is what's tripping you up: xmlns="http://fantasysports.yahooapis.com/fantasy/v2/base.rng" You're asking for elements in the unnamed namespace - but the elements default to the namespace shown above. It's easy to fix that in LINQ... more 1/2/2014 4:13:36 PM

people

Check inside method whether some optional argument was passed

How do I check if an optional argument was passed to a method? public void ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10) { if...
Jon Skeet
people
quotationmark

You can't, basically. The IL generated for these calls is exactly the same: ExampleMethod(10); ExampleMethod(10, "default string"); ExampleMethod(10, "default string", 10); The defaulting is performed at the call site, by the... more 1/2/2014 4:07:23 PM

people

IXmlSerializable implementation ruins xml serialization

I have a class containing a readonly string. Thus I need to manually handle xmlserialization. But it seems that using this class in a grander setting with automatic xml...
Jon Skeet
people
quotationmark

I suspect the problem is that you're not reading to the end of the containing element - I suspect you want: public void ReadXml(XmlReader reader) { Name = reader.ReadElementContentAsString(); } The documentation for ReadXml states: ... more 1/2/2014 3:28:05 PM

people

How to fix my Prepared Statement to give me data from the DB in my application?

I have my Java program and I need to get data from my MYSQL DB, I wrote this one out but its just sysout so getting data from my class and not using the Prepared Statement (I can...
Jon Skeet
people
quotationmark

Well you're not actually executing the prepared statement... you're just preparing it. You should call PreparedStatement.executeQuery and use the ResultSet it returns: // ...code as before... try (ResultSet results = ps.executeQuery()) { ... more 1/2/2014 2:30:09 PM

people

Why isn't my program accessing the superclass' array as expected?

I searched for an answer to this problem for quite some time, and I have done a lot of different tests, and I have narrowed and simplified a bug in my Java Applet down to this...
Jon Skeet
people
quotationmark

You're using b in the constructor of Otherclass - which will be executed before the Applet launcher gets to execute init. If you put this statement: b[0] = 4; into the constructor of Main, it will be executed before the constructor... more 1/2/2014 1:42:07 PM

people

how to get nth letter of english alphabet

Is there any way to get nth letter of English alphabet? I want smt similar to this: string letter = EnglishAlphabet.GetLetter(5); //result -> letter is 'E' I want to use...
Jon Skeet
people
quotationmark

The simplest approach is: public string GetLetter(int value) { char letter = (char) ('A' - 1 + value); return letter.ToString(); } I'd personally change the return type to char though: public char GetLetter(int value) { ... more 1/2/2014 12:11:06 PM

people

Difference between date in miliseconds and its Calendar representation

I have two functions which convert a date String to a date in milliseconds: public static long convertYYYYMMDDtoLong(String date) throws ParseException { SimpleDateFormat f =...
Jon Skeet
people
quotationmark

You're using mm, which is minutes, not months. You want yyyy-MM-dd as your format string. It's not clear why you're not returning a Calendar directly from your method, mind you: private static final TimeZone UTC =... more 1/2/2014 11:34:28 AM

people

Parse date of ISO 8601 value 24:00:00 fails

I'm trying to parse incoming date from data source (which cannot be changed). It gives me time in ISO 8601 format example: 2007-04-05T24:00. How ever in .Net it fails to parse...
Jon Skeet
people
quotationmark

Yes, .NET doesn't support this as far as I'm aware. My Noda Time project does, but only partially: it can parse the value, but the value is just parsed to midnight at the start of the next day, and is never formatted as 24:00. There's... more 1/2/2014 9:37:11 AM

people

Write Base64 encoded image to file

How to write a Base64-encoded image to file? I have encoded an image to a string using Base64. First, I read the file, then convert it to a byte array and then apply Base64...
Jon Skeet
people
quotationmark

Assuming the image data is already in the format you want, you don't need image ImageIO at all - you just need to write the data to the file: // Note preferred way of declaring an array variable byte[] data =... more 1/2/2014 9:18:07 AM

people