Browsing 7239 questions and answers with Jon Skeet

Java mailto Illegal character colon?

im trying to send an email with an attachment, but it keeps saying: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Illegal character in opaque part...
Jon Skeet
people
quotationmark

You're calling URLEncoder.encode, but ignoring the result. I suspect you were trying to achieve something like this: String encoded = URLEncoder.encode(message, "UTF-8"); URI uri = URI.create(encoded); ... although at that point you'll... more 12/16/2014 8:28:04 AM

people

Linq Expression Selector

Expression<Func<T, object>> selector is the selector which I have as a parameter. My method is a generic type and lets say that I want to get multpile property values...
Jon Skeet
people
quotationmark

If you want to get multiple properties out, you could use multiple parameters, where each extracted a single value, but it would be more common to use a lambda expression which creates an anonymous type. For example: var result =... more 12/16/2014 7:36:04 AM

people

Java Casting in Method Overloading

I have the methods overloading such as: public int sum1(int a, int b) { int c= a+b; System.out.println("The method1"); return c; } public float sum1(int a, float...
Jon Skeet
people
quotationmark

TL;DR version of this answer: Variables of primitive types never have a different type at execution-time to their compile-time. (A double is always a double, never a float, etc.) Overload resolution (picking which method signature is... more 12/16/2014 7:25:19 AM

people

selecting some specific xml elements to list of anonymous objects

I have an xml document with main XElement "details" and several "detail" XElements, and for each detail Element i have also several "node" Element, this is a part of my xml ...
Jon Skeet
people
quotationmark

I would actually think about readability before performance, unless you know you have a performance issue. But even so, you can definitely improve the code. I would consider using ToDictionary to convert each detail element into a... more 12/15/2014 4:20:56 PM

people

Delete Files of multiple File types in c#

I have the following solution to delete a single file type with only one extension; however I am trying to find a way to incorporate multiple file extensions, for example: .wma,...
Jon Skeet
people
quotationmark

Well that's just a matter of changing your condition to be "where the extension is any one of a set" and removing the pattern from the GetFiles call. Also note that you don't need to call ToArray() - just iterate over the results: var... more 12/15/2014 4:03:15 PM

people

Compiler Error : An expression tree may not contain a dynamic operation

Consider the following code, which wraps (rather than using inheritance for specific reasons) an instance of Dictionary<string, T> and implements IEnumerable and IQueryable...
Jon Skeet
people
quotationmark

The problem is that your type implements IQueryable<>, so the Queryable method is chosen by member lookup - so the compiler tries to create an expression tree from your lambda expression... and that's what fails. The dictionary... more 12/15/2014 3:06:54 PM

people

String UTF 8 conversion Issue

I am encountering an issue in String conversion to UTF-8. Basically, i have developed a DayDescriptionEnum which will actually, get the day of week and return description...
Jon Skeet
people
quotationmark

UTF-8 is a red herring here. You don't need to convert to UTF-8 and back at all - you just need to fix your strings so that you're not escaping the backslash: SUNDAY(1, "Sunday", "\u0627\u0644\u0623\u062d\u062f"), // etc Within a string... more 12/15/2014 10:39:35 AM

people

Class Initialize() in C#?

In Obj-c there is the static Initialize method which is called the first time that class is used, be it statically or by an instance. Anything like that in C#?
Jon Skeet
people
quotationmark

You can write a static constructor with the same syntax as a normal constructor, except with the static modifier (and no access modifiers): public class Foo { static Foo() { // Code here } } Usually you don't need to do... more 12/15/2014 9:47:06 AM

people

Java Servlet interface is expected here

I am absolutely new to Java. I am creating a Servlet and getting the error interface is expected here. Can you please make me understand the problem(s)? I am using IntelliJ...
Jon Skeet
people
quotationmark

HttpServlet is an abstract class, not an interface - Servlet is an interface, but you rarely implement that directly. Just change this: public class ErpServlet implements HttpServlet { to public class ErpServlet extends HttpServlet {... more 12/15/2014 9:45:13 AM

people

Difference between 2 days in years, months and days

I need to output the difference between 2 days in years, months and days. With timespan and subtract i only get the days but is it possible to output in years, months and...
Jon Skeet
people
quotationmark

The .NET types don't give you a decent answer to this without having to write code to try one answer and adjust appropriately, but my Noda Time project is designed to handle this sort of thing. For example: LocalDate x = new... more 12/15/2014 9:33:08 AM

people