Browsing 7239 questions and answers with Jon Skeet

Should I keep a reference to the original Exception in the top Exception if another Exception eats it?

Consider this custom Exception class: public class CustomException extends Exception { private static final long serialVersionUID = 1L; public static final int...
Jon Skeet
people
quotationmark

No, there's no reason to store the cause yourself when Throwable already has that facility. Your class should only introduce extra information, not duplicate fields which already have a meaning. Aside from anything else, I would expect to... more 6/13/2014 10:57:46 AM

people

Problems with saving data with single quote ' in the query

I have an asp.net project in which I am getting an error while saving data.I have a text box for school name, most school names get saved but if I have a school name like...
Jon Skeet
people
quotationmark

You haven't shown your code, but I strongly suspect that you've got code such as: // Bad code! String sql = "Insert Into tblSchool(SchoolName, CreatedBy, CreatedOn) " + "values('" + name + "'," + creator + ",'" + date... more 6/13/2014 10:33:14 AM

people

Why is this Float constant null when executing the static block?

The following code, when executed, prints nitesh null instead of the expected nitesh 130. Why isn't n initialized before executing the static block? class test { static ...
Jon Skeet
people
quotationmark

str is a compile-time constant - n is not, because it's of type Float. If you change it to final static float n = 130f then you'll see the value in the static initialization block. So currently, in the static initializer block, the value... more 6/13/2014 10:19:17 AM

people

How do java resolve relative path like [ new File("filename.txt") ] ?

When in java I use relative path to create file like this: File file = new File("filename.txt"); How program resolve path? In my program I have an issue related to this. When I...
Jon Skeet
people
quotationmark

It resolves it relative to your process's current working directory. For example, you can specify that in Eclipse in the run configuration. Basically, you should either use an absolute filename, or make sure you're running it from an... more 6/13/2014 8:02:37 AM

people

Breakpoints in Java file not getting detected during ANT Build

I am having a code like one below. package com.mugil.servlet2; public class Sample { static { System.out.println("Hi There"); } public static void...
Jon Skeet
people
quotationmark

Breakpoints don't exist in Java source code at all - nor even in the compiled class files. They're purely a debug-time feature - the debugger instructs the VM where the breakpoints are. The breakpoints you're seeing in your IDE are stored... more 6/13/2014 6:05:17 AM

people

Visual studio 2013 express missing Windows forms C# project template

I just installed a fresh copy of MS Visual Studio 2013 Express on Windows 8.1. After installing I checked out the new IDE. When I create a new C# project I need to select a...
Jon Skeet
people
quotationmark

I suspect you downloaded "Visual Studio Express for Windows": You can use the tools in Visual Studio Express 2013 for Windows to create innovative and compelling Windows Phone and Windows Store apps on Windows 8.1. You want to... more 6/12/2014 8:51:58 PM

people

Convert GUID to string Entity Framework

At the risk of asking a duplicate question, I cannot seem to get this to work. There are many examples of what I want to do but the syntax isnt quite the same and nothing has...
Jon Skeet
people
quotationmark

You want AsEnumerable() to force the ToString() call to be evaluated locally rather than as part of the EF query. For example: using (DBEntities de = new DBEntities()) { string[] roleset = de.MySQLView ... more 6/12/2014 7:46:17 PM

people

Incorrect timezone from server side to Javascript

I have this method in the C# (server) side: protected double GetAccountTime() { return ((DateTime)unit.SomeMethod(DateTime.UtcNow)) .Subtract(new DateTime(1970,...
Jon Skeet
people
quotationmark

A Date object doesn't have any concept of a time zone. It always represents a number of milliseconds since the Unix epoch. You don't need to do any conversions - you've got the right point in time. (Indeed, there's no sense in which you... more 6/12/2014 7:35:21 PM

people

MySQL select query with parameter

I am trying to use MYSQL select query with c#. Following query for searching "ID" is working fine: conn = new MySqlConnection(cs); conn.Open(); cmd =...
Jon Skeet
people
quotationmark

This is the problem: where value = '?cname' That's specifying ?cname as the literal value you're searching for - when you actually just want the parameter. Remove the quotes and it should be fine: where value = ?cname (You should use... more 6/12/2014 6:16:16 PM

people

Required XMLGregorianCalendar date and time in e.g. 2012 06 08T08:16:43+00:00 format (according to the W3C guidelines)

Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String formattedDate = sdf.format(d); //yyyy-MM-dd...
Jon Skeet
people
quotationmark

Your GregorianCalendar is in your system time zone. All you need is: TimeZone utc = TimeZone.getTimeZone("Etc/UTC"); GregorianCalendar gc = new GregorianCalendar(utc); Having said that, it's not clear why you're converting a date to a... more 6/12/2014 2:52:10 PM

people