Browsing 7239 questions and answers with Jon Skeet

joda time, DateTimeFormatter

I have following code dateTimeFormat = ISODateTimeFormat.dateTimeNoMillis() and i use dateTimeFormat below public static String print(Date value) { return...
Jon Skeet
people
quotationmark

In all date instances has the same time zone Europe/Moscow A Date instance doesn't have a time zone - it's just an instant in time. But you should probably specify the time zone for your formatter, e.g. dateTimeFormat =... more 4/22/2015 2:55:45 PM

people

LINQ Left Joins 'System.NullReferenceException' Error

I have been trying to create a LINQ statement that will join 3 tables with left outer joins. When I try to run the code, I am receiving a 'System.NullReferenceException' error. ...
Jon Skeet
people
quotationmark

Just handle item.Language being null in your view: <p>@item.Language == null ? "" : @item.Language.LanguageSpoken</p> In C# 6 this is even simpler: <p>@item.Language?.LanguageSpoken</p> (Assuming that null... more 4/22/2015 2:39:38 PM

people

issue when converting json string to object

I have the following json string [["{\"object\":\"user\",\"entry\":[{\"uid\":\"823602904340066\",\"id\":\"823602904340066\",\"time\":1429276535,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10152579760466676\",\"id\":\"10152579760466676\",\"time\":1429278530,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10203227586595390\",\"id\":\"10203227586595390\",\"time\":1429278537,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10203227586595390\",\"id\":\"10203227586595390\",\"time\":1429278521,\"changed_fields\":[\"feed\"]}]}"]] JsonConvert.DeserializeObject<List<RootObject>>(jsonData); When rrying to convert this into json object with Netwonsoft.json ,I am get getting error "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Model.RootObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly." I am using the following classes public class RootObject { public List<Entry> entry; } public class Entry { public string uid; public string id { get; set; } public int time { get; set; } public List<string> changed_fields { get; set; } } Can some please tell where am i getting it wrong ?
Jon Skeet
people
quotationmark

Your JSON doesn't contain any RootObject objects - it just contains strings. You've got an array of arrays of strings, where each "nested" array just contains a single string, and each string is the JSON representation of a RootObject. If... more 4/22/2015 8:47:03 AM

people

ToList() method using Single() linq query

I have a problem with ToList() method and basically I'm trying to make a function that will return a var linq query convert to a list and here the the function. ...
Jon Skeet
people
quotationmark

You're calling Single(), which means you've got one result. ToList() is an extension method on IEnumerable<T>. If you want to create a list with just that one element, you could write: return new List<UsersTabPage> { firstone... more 4/21/2015 7:29:06 PM

people

Which class gets called first in a java project with many packages?

Is there a class called 'main' or something that java looks for in your project? If it finds it, does the compiler take the 'main.class' as a starting point for compilation? I...
Jon Skeet
people
quotationmark

At compilation time, it doesn't usually matter - you just specify all the source files you want to compile. (You can specify a subset and the compiler will find other source files it needs, but it's better to specify everything you want... more 4/21/2015 4:06:27 PM

people

Return Each Vowels

public class one { public static void main(String [] args) { } public static int vowels( String s ) { int countA = 0; int countE = 0; int...
Jon Skeet
people
quotationmark

You can only return a single value from a method call. However, that value can be an array or a collection. Two options to consider: Change your method to accept a second parameter of "the character to count" occurrences of, and call it... more 4/21/2015 2:50:35 PM

people

Instance Variable Declaration Syntax

I'm seeing what appears to my novice eyes as conflicting conventions in Java, when it comes to declaring instance variables. For example, a classic bank account instance variable...
Jon Skeet
people
quotationmark

Why is this second syntax ok when it looks like it deviates wildly from the first? It doesn't deviate at all from the first. Part First example Second example Access modifier private ... more 4/21/2015 12:35:56 PM

people

Wrong method is called

The below code might look odd in functionality. This is because this is a simplified presentation of something bigger. I have a class named Person and the person has 1 property...
Jon Skeet
people
quotationmark

My goal with ClassRoom(Person person) is that, if the Person is null, ClassRoom() is called and if it's not null ClassRoom(Person person, string name) is called. You can't do that, basically. You can't decide which constructor to... more 4/21/2015 10:14:34 AM

people

What does assigning a static field to an instance field not point both at the same object

In this fiddle, we are assigning a static field to an instance field. When we change the static one, the instance one still has the initial value. Why is that? We thought that...
Jon Skeet
people
quotationmark

In this fiddle, we are assigning a static field to an instance field. Right. That copies the current value of the static field to the instance field. It doesn't tie the variables together forever - it just copies the current... more 4/21/2015 5:54:39 AM

people

java : Returning stream or resulting bytes

I have need to return the byte array for the ByteArrayOutputStream from the called method. I see two ways to achieve the same thing: firstly to return ByteArrayOutputStream &...
Jon Skeet
people
quotationmark

There's another alternative: return an InputStream. The idea is presumably that you're returning the data resulting from the operation. As such, returning an output stream seems very odd to me. To return data, you'd normally either return... more 4/21/2015 5:51:33 AM

people