Browsing 7239 questions and answers with Jon Skeet

cannot find symbol, keyEvent constants java

I've created a Map containing a KeyEvent constant as key and a JButton as data and I add them to the Map inside a createButton function: /*TouchType.java*/ import...
Jon Skeet
people
quotationmark

You appear to be expecting to be able to reference constants from KeyEvent without either importing them or qualifying them. You should either have: row1.add(createButton(KeyEvent.VK_DEAD_TILDE, "~")); Or add: import static... more 10/30/2015 3:18:59 PM

people

Is there a better reference container than a one element array?

A Java anonymous class can only access a variable from the surrounding method if that variable is final, and hence the inner class can't write to that variable. In order to...
Jon Skeet
people
quotationmark

There's AtomicReference<T> which is what I'd normally use. final AtomicReference<String> ref = new AtomicReference<String>(); final Runnable runnable = new Runnable() { public void run() { ref.set("Hello... more 10/30/2015 2:14:47 PM

people

Why does XmlTextReader fail on calling an unsupported Stream.Length?

I have an XmlTextReader, and I pass it in a System.Net.ConnectStream. If I enter the debugger, I can see that ConnectStream does not support the Length property and this throws a...
Jon Skeet
people
quotationmark

If a Stream returns true from CanSeek, it assumed that Length, SetLength, Position and Seek are all supported. Some code may test CanSeek and use the result to optimize its behaviour - as seems to be the case here. When you return true... more 10/29/2015 8:30:29 PM

people

Dictionary<TKey,object> modify indexer to cast before returning value

I've seen this in a question: : edit: type's are known before adding to dictionary You could use Dictionary<string, object>, then you'd need to cast the results: int no...
Jon Skeet
people
quotationmark

(Answered before the .NET 2.0 requirement was mentioned - it may still be useful for others.) You can use a Dictionary<string, dynamic> instead - at which point the compile-time type of the expression dict["stringObject"] will be... more 10/29/2015 11:57:21 AM

people

How to convert String to BigDecimal without scientific notation

I am trying to convert String value to BigDecimal value. when i use 0.000001234 I am getting same value in BigDecimal. But, when I use 0.000000123 or 0.000000012 I am getting...
Jon Skeet
people
quotationmark

You're converting the String to a BigDecimal with no problems. The BigDecimal value has no notion of whether the value has exponential notation or not... it's just a scaled value. The problem you're seeing is when you implicitly call... more 10/29/2015 11:42:04 AM

people

find the compiled class version number

My project consists of some third party jar files, which was compiled in different version of java. My project is using older version of java so i am getting...
Jon Skeet
people
quotationmark

You can use javap (with -v for verbose mode), and specify any class from the jar file. For example, looking at a Joda Time jar file: javap -cp joda-time-2.7.jar -v org.joda.time.LocalDate Here the -cp argument specifies the jar file to... more 10/28/2015 4:13:17 PM

people

How can I add 1 second in Joda date/time?

I have a LocalDateTime object myDateTime that I can see in the debugger that has: 2015-12-12T23:59:59.000 I do: myDateTime.plusSeconds(1) but the timestamp remains the same. What...
Jon Skeet
people
quotationmark

Most types in Joda Time (at least the ones you should use) are immutable. You can't change their value - but you can call methods which return a new value. You're calling the right method in this case, but you need to remember the result,... more 10/26/2015 8:48:26 PM

people

Variable x might not have been initialized error

I just do not see why this isn't working: public class HelloWorld { public static void main(String []args) { int a = 9; boolean isOdd; if (a != 0) { ...
Jon Skeet
people
quotationmark

The compiler doesn't consider a != 0 and a == 0 to be mutually exclusive conditions - or rather, it doesn't look at whether two if conditions are mutually exclusive to work out what happens. So you can fix the error by changing your code... more 10/26/2015 8:42:27 PM

people

Creating an object in C# with or without new

I have the following classes: public class Product { public int ProductID { get; set; } public string Name { get; set; } public string Description { get; set; } ...
Jon Skeet
people
quotationmark

In ShoppingCart class, there's private LinqValueCalculator calc; from my understanding we are creating an object from that class No, it doesn't. It declares a variable of that type, but it doesn't create any objects. Initially, that... more 10/24/2015 11:16:14 AM

people

Why do i keep getting a cant find symbol error

I am trying to store one of three items a book, cd, or dvd into an array but my add method is not working. here is the GUI Class. /** Class BookStoreApplication GUI...
Jon Skeet
people
quotationmark

Firstly, you would have fewer problems if you followed Java naming conventions - currently Catalog is both an array variable name and a type name. Secondly, there is no add method in arrays. You may want a List, e.g. ArrayList.... more 10/24/2015 3:36:52 AM

people