Browsing 7239 questions and answers with Jon Skeet

Not getting the correct timezone in java

The code that I am using to get the current timezone in java side is as follows: Calendar calendar =...
Jon Skeet
people
quotationmark

You're calling the parameterless getDisplayName() method whose documentation includes: This method is equivalent to: getDisplayName(false, LONG, Locale.getDefault(Locale.Category.DISPLAY)) The false here is the argument which... more 3/10/2014 11:57:10 AM

people

Writing image not working properly using BufferedOutputStream

Iam reading and writing an image file in java.the file can be of any type so i used buffered reader and writer while writing image its not written properly.The image get...
Jon Skeet
people
quotationmark

This is the problem: bufferedReader = new BufferedReader(new InputStreamReader(dto.getInputStream())); You're using an InputStreamReader, which means it's reading the binary data as text. Don't do that. Your OutputStream is fine, it's... more 3/10/2014 10:56:00 AM

people

Get date by utc/gmt in Android

I want to display the time in some Country, and the TimeZone is GMT+4. private void loadWeather(){ TimeZone tz = TimeZone.getTimeZone("GMT+0400"); Calendar cal =...
Jon Skeet
people
quotationmark

The problem is that you're specifying the time zone just on the Calendar - which is only used to get the current instant in time, which doesn't depend on the time zone. You need to specify it on the format instead, so that it's applied... more 3/10/2014 10:17:07 AM

people

Object reference not set to an instance of an object error in json

i am trying to develop json feed below format { "contacts": [ { "id": "c200", "name": "Ravi Tamada", "email":...
Jon Skeet
people
quotationmark

This is the problem, in your object initializer: phone={mobile="ff",home="ff",office="ff"} That's trying to set properties of an existing Phone object. In other words, it's performing: var tmp = new Cont(); tmp.sno =... more 3/10/2014 7:36:48 AM

people

How to convert a byte in binary representation into int in java

I have a String[] with byte values String[] s = {"110","101","100","11","10","1","0"}; Looping through s, I want to get int values out of it. I am currently using this Byte b...
Jon Skeet
people
quotationmark

You're using the Byte constructor which just takes a String and parses it as a decimal value. I think you actually want Byte.parseByte(String, int) which allows you to specify the radix: for (String text : s) { byte value =... more 3/10/2014 6:39:07 AM

people

How to make object referencing to the same thing?

public class Number { private int j; public Number(){ j = 3; } public Number(int m){ j = m; } public void SetNum(int n){ j = n; ...
Jon Skeet
people
quotationmark

Others have suggested creating just one User object. An alternative would be to have two User objects, but with the same reference for the value of the jim field: User keith = new User(); User justin = new User(); justin.jim =... more 3/10/2014 6:19:23 AM

people

Incorrect modulo results in Java

I'm trying to run some elliptic curve results in java, but the modulo operator doesn't seem to output the right results. int a = 17; double previousx = 4; double previousy =...
Jon Skeet
people
quotationmark

8 and 55 are correct, but -57 mod 59 = 2 and not -57. How do I fix this? The % operator in Java isn't modulus - it's the remainder operator. It's behaving entirely correctly according to the language specification. When you suspect... more 3/9/2014 5:39:56 PM

people

Java won't export my resources properly

So I have 2 class folders one is res the other is lib. My res folder has two other sub folders one with images the other with sounds. My lib folder has 4 other jar files and a...
Jon Skeet
people
quotationmark

I am to call my images I am using ImageIO.read(new File(imagePath)) Contrary to your title, this is not an Eclipse problem - it's simply a bug in your code, because your code assumes that the image is stored as a file in the file... more 3/9/2014 4:40:37 PM

people

Error in C#: "an expression tree may not contain a base access" why not?

I was calling a method that accepts Expression<Func<bool>>. As part of the expression I was passing: this.Bottom == base.lineView.Top The compiler gave me an error...
Jon Skeet
people
quotationmark

Looking at the System.Linq.Expressions.Expression documentation, I don't think there's an expression type which represents "base member access". Don't forget that even though in your case it meant the same as just this, in other cases it... more 3/8/2014 7:55:40 PM

people

Converting Dictionary<string, string> into multiple 1D int[] arrays

How can I convert a dictionary<string, string> into a number of one dimension integer array at runtime? For example, Dictionary<string, string> dic = new...
Jon Skeet
people
quotationmark

Well for there to be separate variables, you'll need to know all the numbers involved at compile-time. (You can't just generate more variables at execution time... and you really don't want to get into the business of working out the word... more 3/8/2014 1:47:08 PM

people