Browsing 7239 questions and answers with Jon Skeet

Connection refused: connect Error in Java + Hibernate

I am trying to do this tutorial and when I got to the hibernate part, I get this errors: java.sql.SQLException: Network error IOException: Connection refused: connect at...
Jon Skeet
people
quotationmark

localhost will always be the server your Java is running on - it's saying "Talk back to the same machine". If your database is hosted on a different server, you need to put that server name in the configuration. more 1/14/2014 1:16:15 PM

people

C# Get dictionary from DLL

I have class library project, where I have some methods and dictionaries public static Dictionary<string, Instruments> globalInstruments; public static...
Jon Skeet
people
quotationmark

You're currently just getting the field - you need to get the value of the field using the GetValue method: var dictionary = (Dictionary<string, WidgetInfo>) f.GetValue(null); Here the null argument is because it's a static field.... more 1/14/2014 11:15:42 AM

people

The type or namespace name 'async' could not be found

I am trying to use the following method in a WPF application .NET Framework 4 Client Profile but I receive this error: The type or namespace name 'async' could not be...
Jon Skeet
people
quotationmark

Well, there are two things: You need to be using a C# 5 compiler, e.g. VS2012. If you're using VS2010, you can't use async. Given the error message, I suspect that you're using the wrong compiler version. You need to use the... more 1/14/2014 8:12:08 AM

people

How would you unmarshall the following with JAXB

How would one unmarshall the following XML response with JAXB into a domain class: <?xml version="1.0"...
Jon Skeet
people
quotationmark

Have you tried using @XmlValue instead of @XmlElement for the time field? After all, it is the value of the root element, rather than a sub-element. I've now tried this with the file supplied, and it works properly. more 1/14/2014 6:48:47 AM

people

Why for creation of delay the static refrence to Thread.sleep is preferred not this.sleep?

In the code below the compiler suggested me to use Thread.sleep (the static reference ) not this.sleep, why is that? public class CThreadUsingThread extends Thread{ public...
Jon Skeet
people
quotationmark

Your code is misleading, basically. It looks like you're referring to a specific thread, when actually it's just calling the static Thread.sleep method which always refers to the currently executing thread. In this particular case it's... more 1/13/2014 7:51:47 PM

people

Inside of using block, need to dispose and reinstantiate

I am trying to enhance the performance of writing thousands of rows to a db using EF. I have found that the speed of SaveChanges() degrades over time within a single context, and...
Jon Skeet
people
quotationmark

It sounds like you basically want to process a collection in batches. That's simple using MoreLINQ (also on NuGet): foreach (var batch in dataToUpload.Batch(100)) { using (var context = new Context()) { foreach (var item... more 1/13/2014 7:47:22 PM

people

List passed into method and deserialised becomes empty once method returns

I have a method: static <E extends NotesAttached> void deserialise(List<E> list, String type) { String fileName = "C:/temp/SalesModel." + type + ".list.ser"; ...
Jon Skeet
people
quotationmark

The list you've deserialized doesn't "become empty" - but the deals variable doesn't refer to the list you've just deserialized... it refers to the same empty list that it did before you called the method. Changing the value of the list... more 1/13/2014 7:27:42 PM

people

Casting an Object is making it become null

In a call back like this: this.Model.LoadStudent(student_key, (o, a) => { var student = o as Students; If I put...
Jon Skeet
people
quotationmark

You're not casting - you're using the as operator. If you instead actually cast, I suspect you'll get an exception: var student = (Students) o; I suspect you've actually got multiple types called Students, and if you really cast instead... more 1/13/2014 6:43:08 PM

people

How to define my own main method in WPF

I would like to override orignal main method in WPF. I want add content at the beginnig of the origina main method. How to do it? It seems that it has to be done in...
Jon Skeet
people
quotationmark

I don't believe you can, directly. The designer introduces its own Main method. What you can do is create your own separate class with a Main method, which in turn calls App.Main when you want to: using System; namespace... more 1/13/2014 5:15:42 PM

people

DOM XML How to get child node?

I have xml like this: <param> <name>some_list</name> <value> <items> <item> <value>7</value> ...
Jon Skeet
people
quotationmark

getElementsByTagName returns all descendant elements. You just want all immediate child elements. You can use getChildNodes() and then filter them if you want. For example: NodeList children = element.getChildNodes(); for (int i = 0; i... more 1/13/2014 4:39:00 PM

people