Browsing 7239 questions and answers with Jon Skeet

ASP.NET Razor Code How to create begin with logic true in conditional statement?

I'm trying to create a logic like that returns true if values are begin-with or start-with some specific value. For example - I'm finding something similar to == Equality term...
Jon Skeet
people
quotationmark

It sounds like you want something like: @{Year == 2014 && Month == 4 ? "True" : "False"} more 4/28/2014 6:19:38 PM

people

Updating object Linq'd from collection doesn't update the object in collection

I have two simple classes. One is called UseCounter<T> and is a simple container for other objects while holding some information about its use (how many times it's been...
Jon Skeet
people
quotationmark

This is the problem: this._elements = elements .Distinct() .Select(e => new UseCounter<T>(e)); This is lazy. Every time you iterate over _elements, it will go back to the original source data, find a distinct set, and... more 4/28/2014 5:03:51 PM

people

NullPointerException if checkbox is not cheked

I am having a checkbox in html like this : <input type="checkbox" name="subscribe" value="subscribe">Subscribe For Answers</input> And in my servlet i get its...
Jon Skeet
people
quotationmark

If the checkbox is not checked, the request won't contain any subscribe parameter, so checked will be null. You want something like: String checked = request.getParameter("subscribe"); if (checked != null && !checked.isEmpty()) { ... more 4/28/2014 4:47:52 PM

people

Disappearing default constructors

I've gotten a number of crash reports with the following stack traces (names changed): Caused by: java.lang.InstantiationException: can't instantiate class...
Jon Skeet
people
quotationmark

Note: this turned out not to be the issue in this case, but if you're reading this question because you've faced the same symptom, it could be the issue for you... According to my understanding of the Java spec, this means that the... more 4/28/2014 4:08:57 PM

people

String based DateTime format or pattern check

I have a datetime string. string strDate = "20140424_18255375"; How to verify the datetime is having in this format YYYYMMDD_HHmmssff I tried: bool isTrue =...
Jon Skeet
people
quotationmark

Using TryParseExact is the right way to go about it, but you need to use the right format specifiers. In this case, I think you want: bool valid = DateTime.TryParseExact(strDate, "yyyyMMdd_HHmmssff", ... more 4/28/2014 11:50:44 AM

people

SQL Statement Presumably runs, no errors, but assertion fails

So I got this issue where I have to try and book all seats in a flight. I've made a Helper class with static methods, which is used for Unit Testing purposes. When I run the test...
Jon Skeet
people
quotationmark

You're never executing the statement: conn.prepareStatement("" + "UPDATE SEAT" + "SET reserved='1337',booked='1337',booking_time='1337'" + "WHERE plane_no='" + plane_no + "';" ); conn.commit(); You're ignoring... more 4/28/2014 11:07:08 AM

people

Java: What happens to the supposed to be initialized members when passing a value to their object at creation time?

This question is more about having a proper Java program construction. I was wondering: What happens to the public Clazz { this.someClazz = new SomeClazz(); } ...
Jon Skeet
people
quotationmark

You need to distinguish between variables, objects and references. The values of x and y are not objects - they're just references. The assignment operator just copies the value from the expression on the right to the variable on the... more 4/28/2014 6:10:58 AM

people

Call parent constructor in java

I have two class Parent and Child, while the Parent have a constructor which needs 3 arguments: class Parent{ public Parent(String host,String path,int port){ } } And...
Jon Skeet
people
quotationmark

The call to super must be the first statement in the constructor body. From section 8.8.7 of the JLS: The first statement of a constructor body may be an explicit invocation of another constructor of the same class or of the direct... more 4/28/2014 6:06:16 AM

people

Getting strange characters when try to get location info with google's geocode api

In my app a try to get location names via tapping on google map. Everything works fine except for the character encoding. My output is like: 1144 Budapest, Ond vezér útja 35,...
Jon Skeet
people
quotationmark

This is the problem: while ((b = stream.read()) != -1) { stringBuilder.append((char) b); } That's effectively using ISO-8859-1. Instead, you should create an InputStreamReader from the InputStream, specifying UTF-8 as the encoding... more 4/27/2014 6:55:42 PM

people

Handle Multiple Timezones in MySQL

     I am using MySQL database for my Application. I am using Java (with Spring) for my web development and Apache Tomcat for Application Server. In my...
Jon Skeet
people
quotationmark

So will it give me wrong logged time for userId 3 and 4 or not? If wrong, what is solution for it? If you actually record the value with GMT+0 won't give you the wrong answer. It doesn't matter what the local time is for the user -... more 4/27/2014 4:09:37 PM

people