Browsing 7239 questions and answers with Jon Skeet

Thread is not acquiring monitor after notify calls

I just made one producer and one consumer thread. When list is empty consumer went to waiting state, then producer insert an item in list and calls notify() to invoke consumer...
Jon Skeet
people
quotationmark

Your producer and consumer are each synchronizing, waiting and notifying their own monitor. You need to give them a shared monitor to use for synchronization etc. For example: Object monitor = new Object(); product pro = new... more 10/7/2014 7:30:54 AM

people

Why is this Java program showing no error?

Consider the below code, I forgot to define the method name, just the code within the block. public class Demo { { Apple ap; // Display price of Winesap. ...
Jon Skeet
people
quotationmark

What you've got there is an instance initializer, as described by section 8.6 of the JLS. It's executed before the body of any constructor when an instance is created - just like field initializers. more 10/7/2014 7:14:28 AM

people

Writing data to text file in table format

So far I have this: File dir = new File("C:\\Users\\User\\Desktop\\dir\\dir1\\dir2); dir.mkdirs(); File file = new File(dir, "filename.txt"); FileWriter archivo = new...
Jon Skeet
people
quotationmark

You're currently including " \r\n" within your right-aligned second argument. I suspect you don't want the space at all, and you don't want the \r\n to be part of the count of 20 characters. To left-align instead of right-aligning, use... more 10/7/2014 5:46:46 AM

people

Could not find the file specified?

I get a really annoying error, code is fine but it can't find the files. Output: .\res\shadersbasicVertex.vs (The system cannot find the file specified) <-- yes it does...
Jon Skeet
people
quotationmark

Well yes, presumably fileName is "basicVertex.vs". Put that on the end of "./res/shaders" and you'll get .\res\shadersbasicVertex.vs. You need an extra slash: shaderReader = new BufferedReader(new FileReader("./res/shaders/" +... more 10/6/2014 6:39:00 PM

people

Why is the wrong method called: Strange inheritance behaviour

So this question is about inheritance and method overriding. Specifically: the case when a child class has a same-name method as the parent, but with a different signature,...
Jon Skeet
people
quotationmark

I'm guessing that you expected m4.E to be printed. But don't forget that overload resolution is performed at compile-time, not at execution time. Neither C nor B have a method4(E) method available, so the compiler resolves the calls to... more 10/6/2014 4:42:59 PM

people

How do I access the nested Class?

I have the following three classes defined. public class FrequencyRecord { public double Frequency; public int Duration; } public class EntryRecord { public string...
Jon Skeet
people
quotationmark

The problem is that you've created an array, but that array is just full of null references to start with. You'd need something like: EntryRecord record = new EntryRecord(); record.Name = "Peter"; IntProfile.Entries[1] = record; to... more 10/6/2014 3:10:27 PM

people

Control.Invoke method not returning

I'm trying to parallelize my code to make it run faster. So far, it's been all headaches and no results. I want to update several DataGridViews at the same time : ...
Jon Skeet
people
quotationmark

I assume you're calling Parallel.Invoke from the UI thread. If so, that's the problem. Parallel.Invoke blocks until all the calls finish... which means you're blocking the UI thread. The tasks you're starting can't complete, because... more 10/6/2014 2:06:49 PM

people

NodaTime Errors after time switch

Yesterday Uruguay changed their clocks, and now I keep seeing exceptions when converting specific times for their timezone: ERROR Exception: - DateTime...
Jon Skeet
people
quotationmark

Yes, it is aware that it's an invalid local time - which is why when you specifically ask it to convert that local time into UTC, it throws an exception. It's roughly equivalent to calling Math.sqrt(-1). The InZoneStrictly call you're... more 10/6/2014 12:03:17 PM

people

Bug in .NET's DateTime.ToString("R") with UTC dates?

I'm based in the UK (GMT+1 time at the moment). If I run this: > DateTime.UtcNow.ToString("R") // Or... > DateTime.Now.ToUniversalTime().ToString("R") "Mon, 06 Oct 2014...
Jon Skeet
people
quotationmark

It's definitely not a bug, it's the documented behaviour: The custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". When this standard format specifier is used, the formatting or parsing operation always uses the invariant... more 10/6/2014 10:31:24 AM

people

Parsing a date works in IDE but not when running from a runnable JAR file

I'm having a problem with Date Parsing. I am getting dates from JXDatePicker and need to re-format them in order to send a query to MySQL. the date I get from JXDatePicker is in...
Jon Skeet
people
quotationmark

Don't parse the result from JXDatePicker at all. It allows you to get the value directly as a java.util.Date (and time zone). Wherever possible, avoid converting to/from text. In this case, there's no need for text anywhere - you can get... more 10/6/2014 9:33:26 AM

people