Browsing 7239 questions and answers with Jon Skeet

Call to super must be first statement error

I'm trying to compile this and it keeps spitting out 6 errors stating error:call to super must be first statement in constructor - I'm really confused and have not been able to...
Jon Skeet
people
quotationmark

All of the anonymous inner classes appear to include the generated code, as if you'd decompiled an existing class file (which I suspect you have). Each time you have something like this: jmenuitem1.addActionListener(new ActionListener()... more 12/3/2014 7:11:00 AM

people

Retrieve Record from Database based on Local Time

Let's suppose I live in a timezone where Today Date is: 12/3/2014 Before saving record I save the date in UTC, so it would be 12/2/2014 user.Created = DateTime.UtcNow; Now I...
Jon Skeet
people
quotationmark

Now that we know that the value is stored as a DateTime (in UTC), you just need to find the UTC time of midnight at the start of today, and the UTC time of midnight at the end of today. If you're happy to use the system time zone, you... more 12/2/2014 2:15:08 PM

people

Bind function (delegate) arguments

I'm trying to achieve the following without using lambda function: Func<bool> test = () => RunSomething("test"); <-- This work fine but creates...
Jon Skeet
people
quotationmark

Well it's easy to build such a method, but that would use a lambda expression for the implementation: public Func<TResult> Bind<T, TResult>(Func<T, TResult> func, T arg) { return () => func(arg); } And likewise... more 12/2/2014 1:48:18 PM

people

Insert syntax error in oledbconnection

What is the problem in this code? for (int i = 1; i <= kalanum; i++) { foreach (Control ctr in panel1.Controls) { if (ctr is TextBox...
Jon Skeet
people
quotationmark

There are three problems here: You're using four parameters, but only specifying 3 of them. (Comments suggest that you're specifying the other one outside the loop) On any one iteration you're only populating at most one of the... more 12/2/2014 11:53:27 AM

people

How to Convert python time.time() to Java

How do I convert the following python code to Java? import time str(int(time.time() * 1e6)) I have tried the following snippet in my Java project. private static String...
Jon Skeet
people
quotationmark

The two values you're getting are very similar - it's just that the representations are different. That's primarily because in the Java version you're multiplying by 1e6 which is a floating-point literal, so the result is a double, which... more 12/2/2014 11:04:54 AM

people

On searching documents in mongodb collection using ISODate range, I get the error "String was not recognized as a valid DateTime"

I am trying to query MongoDB using the following - List<BsonDocument> list = NoSqlBusinessEntityBase.LoadByWhereClause("peoplecounting", string.Concat("{siteid:\"",...
Jon Skeet
people
quotationmark

It's not entirely clear, but I suspect the problem may well be how you're formatting the date. This: old.ToString("yyyy-mm-dd hh:mm:ss") should almost certainly be this: old.ToString("yyyy-MM-dd HH:mm:ss") or... more 12/2/2014 9:48:10 AM

people

Where can I find System.Web.HttpContext.Current.Server dll?

Where can I find System.Web.HttpContext.Current.Server dll. I want to use Server.MapPath() in my code and it requires System.Web.HttpContext.Current.Server namespace. Even from...
Jon Skeet
people
quotationmark

System.Web.HttpContext.Current.Server isn't a namespace. Let's break it down: System.Web is a namespace HttpContext is a type (in the System.Web assembly) Current is a static property within HttpContext, returning an HttpContext... more 12/2/2014 7:00:57 AM

people

Compile time error when adding an Integer to a generic ArrayList of String

I know this question has been asked multiple times before but I'm looking for an answer based on type erasure. Why does the compiler give an error on adding Integer to...
Jon Skeet
people
quotationmark

Even though type erasure means that at execution time the VM can't distinguish between an ArrayList<String> and an ArrayList<Integer> (they're both just instances of ArrayList) the compiler does know about the type argument,... more 12/2/2014 6:54:31 AM

people

Write to file with FileStream without using "using"

I have a class member variable _stream which is a FileStream. This variable gets initialized in the constructor and needs to stick around until I'm done with the class. I have...
Jon Skeet
people
quotationmark

Firstly, you clearly need to remove the using (_stream) as that will dispose of the stream directly. Secondly, the StreamWriter will also dispose of the stream as well, with your current code. Options for this are: Don't have a using... more 12/1/2014 5:25:51 PM

people

Java Reflection Class

Why is second SOP showing output as true here, I was hoping it would display false like first SOP ? public class reflect1 { public static void main(String[] args) { ...
Jon Skeet
people
quotationmark

The values of obj1 and obj2 refer to different objects - when you use == in Java and both operands are references, the result is to compare whether those references refer to the exact same object. In this case you've got two different... more 12/1/2014 4:27:57 PM

people