Browsing 7239 questions and answers with Jon Skeet

Odd NullPointerException

Stacktrace from my NPE starts with: Caused by: java.lang.NullPointerException at pl.yourvision.crm.web.servlets.listExport.ProductListExport.writeCells(ProductListExport.java:141) Line number 141 in this file is: Double availablePieces = store != null ? store.getAvailablePieces() : 0.0; Where store is not null and store.getAvailablePieces() is null. I do not understand why I get exception in here. Any ideas?
Jon Skeet
people
quotationmark

I'm 99% sure this is because of the behaviour of the conditional operator. I believe your code is equivalent to: double tmp = store != null ? store.getAvailablePieces() : 0.0; Double availablePieces = tmp; In other words, it's unboxing... more 1/23/2014 10:45:59 AM

people

NullPointerException with HashMap<Integer,Double> when input is double

Introduction I am having some difficulties with figuring out what's causing me to get a NullPointerException in a HashMap that should be fairly simple. To understand why I am...
Jon Skeet
people
quotationmark

1) Why am I getting Exception in thread "main" Because there's presumably no value for the given integer, so the get call returns null. You're then unboxing that, which throws an exception. Your code is effectively: public static... more 1/23/2014 10:31:24 AM

people

SimpleDateFormat returns wrong date value during parse

I m facing a problem:I want to get current time of GMT TimeZone in long. I m using the following code as given below: TimeZone timeZoneGmt = TimeZone.getTimeZone("GMT"); ...
Jon Skeet
people
quotationmark

You've misunderstood how Date works. A Date doesn't have a time zone - if you use Date.toString() you'll always see the default time zone. The long value in a Date is purely the number of milliseconds since the Unix epoch: it doesn't have... more 1/23/2014 10:18:52 AM

people

Program stucks on creation of class object in java

I have a parent class "Application Window" and a child class "config". When I am creating an object of "config" class execution tends to go into a loop and keeps on creating this...
Jon Skeet
people
quotationmark

This is the problem: public class config extends ApplicationWindow in conjunction with this in the ApplicationWindow constructor: cfg = new config(); So to create a new ApplicationWindow, you need to create a new config... but... more 1/23/2014 8:57:34 AM

people

classes and threading

I have the following code: public class Search { StringBuilder sb = new StringBuilder(); string[] myparams; public void Start() { //Start search threads ...
Jon Skeet
people
quotationmark

Without seeing the actual code for GetFirstRequest and GetSecondRequest, we can't tell - but the fact that you've got an instance variable of type StringBuilder makes me skeptical. StringBuilder itself isn't thread-safe, and if you're... more 1/23/2014 8:53:54 AM

people

Warning message in async method saying that it lacks await operators

I have a excel download in my asp.net mvc 4 application. When I click the export button the below controller method gets called. Since I need it to be done asynchronous, I am...
Jon Skeet
people
quotationmark

Am I doing something wrong? Well, you're not really doing anything asynchronously. Your ReportExcelAsync method is entirely synchronous, as it doesn't have any await expressions. So GenerateReportExcel will call ReportExcelAsync,... more 1/23/2014 8:41:25 AM

people

Why must JRE be installed on a machine if it's referenced and packaged in my project?

I exported my project to an executable jar and noticed that eclipse also packaged the external jars I used. When trying to run it on a different machine (which did not have JRE...
Jon Skeet
people
quotationmark

The JRE is more than just the libraries you're referring to - it's the whole JVM. Also, the JRE wouldn't be included in "external jars" anyway. It's generally assumed that the target of a Java application will already have Java installed -... more 1/23/2014 7:15:48 AM

people

avconv tool executed from Java run time stops encoding after 8 minutes

Here I am trying to encode live rtmp stream coming from Flash Media Server and broadcasting low bit rate stream by using avconv tool of Libav. Libav is installed on Ubuntu OS....
Jon Skeet
people
quotationmark

I assume this code is meant to drain stdout/stderr from the process: int c1; while ((c1 = in1.read()) != -1) { System.out.print((char)c1); } int c; while ((c = in.read()) != -1) { System.out.print((char)c); } Unfortunately, it... more 1/23/2014 6:52:44 AM

people

NSDateFormatter not returning proper date

All, I have an NSDateFormatter, and it doesn't seem to be returning the proper month. Below is my code: - (NSDate *)stringToDate { NSDateFormatter *df = [[NSDateFormatter...
Jon Skeet
people
quotationmark

I think the problem is that DD is "day of year" rather than "day of month" - and YYYY is a "week year" rather than just "year". (Week years are odd, basically. Best to just ignore them if possible :) So try formats of "yyyy-MM-dd" and... more 1/22/2014 8:08:07 PM

people

Change format of Array string

I currently run an array which reads 6 or so lines from a text file. Below is an example of how i'm extracting the required information from the lines in the text file line =...
Jon Skeet
people
quotationmark

Currently you're never parsing the values as DateTime values - which means you can't format them as DateTime either. The only single-parameter ToString method on String is the one with IFormatProvider as the parameter type, which is why... more 1/22/2014 7:34:26 PM

people