Browsing 7239 questions and answers with Jon Skeet

Java local object variable's scope

I'm trying to pick up Java again using the book Data Structures & Algorithms in Java, in pg 191, the book implements link list. The code first builds a link class, a link list...
Jon Skeet
people
quotationmark

The value of the newlink variable in insertFirst is copied into the instance variable here: first=newlink; Then in displayLink, the value of first is copied back into a local variable: link current=first; It's important to... more 1/22/2014 7:24:49 PM

people

Why does this give an unchecked cast warning?

Consider this example: interface A<T> {} interface B<T> extends A<T> { void run(); } class Test { public void main(String[] args) { ...
Jon Skeet
people
quotationmark

When this happens normally, it means that the cast isn't really checking anything. Here's a concrete example: import java.util.*; public class Test { public static void main(String args[]) { List<String> strings = new... more 1/22/2014 6:50:57 PM

people

Bit Shifting wrong value

I have a problem, I need to convert coordinates using shift, and after that convert them back to original but it returns not the same value (min,max values can't be...
Jon Skeet
people
quotationmark

The problem is that your shift is effectively dividing by 16... so you end up losing information. You can't exactly represent any values which aren't exactly divisible by 16 (i.e. values which don't have the bottom four bits as 0000.) If... more 1/22/2014 6:20:49 PM

people

How to include line number and file name Console.WriteLine output?

Is there a way to include line numbers and file name in C#'s Console.WriteLine function? For example, on the line 115 of file "myClass.cs" I have the...
Jon Skeet
people
quotationmark

If you're using C# 5, you can use caller information attributes to do this. For example: using System; using System.IO; using System.Runtime.CompilerServices; public class Test { static void Log(string message, ... more 1/22/2014 6:18:20 PM

people

Compiler error when not including the parameter types from another constructor

I'm using C# under VS2012 v.11.0.61030.00 Update 4. I have a class with two constructors: one for normal use, and one that injects a dependency for the purposes of unit...
Jon Skeet
people
quotationmark

It's okay not to understand a particular class when you know that its use is in a member that's definitely not applicable for the call you're making, because you're specifying two arguments and the member only takes one parameter. It's... more 1/22/2014 4:31:52 PM

people

Java class and return

I have a stupid question for you guys, since I get an error with this code. This is my first Stackoverflow post, so sorry if I did any mistakes. I want to return a boolean (true...
Jon Skeet
people
quotationmark

The problem is that if an exception is thrown, you catch it and then drop to the end of the method without returning a value. What do you want the caller to see at that point? I suspect you either want to let the exception propagate up... more 1/22/2014 4:11:22 PM

people

Check isDaylightSavingTime for

The Using Time Zones Guide shows how to check if daylight saving time (DST) is in action for the current date and how to get the next date when daylight saving time changes. With...
Jon Skeet
people
quotationmark

You just need to call isDaylightSavingTimeForDate, passing in the relevant NSDate. It's not that isDaylightSavingTime itself has two parameters - it's that it calls isDaylightSavingTimeForDate with the current date. From the docs for... more 1/22/2014 4:05:34 PM

people

Insert a string in the middle of text file without replacing

Suppose i have a text file named Sample.text. i need advice on how to achieve this: Sample.txt before running a program: ABCD while running the program, user will input string...
Jon Skeet
people
quotationmark

Basically you've got to rewrite the file, at least from the middle. This isn't a matter of Java - it's a matter of what file systems support. Typically the way to do this is to open both the input file and an output file, then: Copy the... more 1/22/2014 3:16:34 PM

people

Why I'm getting Incorrect syntax near ')' error?

I'm trying to create a registration page using C# on Visual Basic 2012. When I debug I get 0 errors, but when I try to register an account I get the following error. ...
Jon Skeet
people
quotationmark

You haven't specified any parameters in your SQL, or a VALUES section - you're saying "I want to insert into these fields..." but not what you want to insert. It should be something like: string insCmd = "Insert into Accounts... more 1/22/2014 2:35:53 PM

people

Ffmpeg stop read data from streaming from 104 MB

When i launch this command in shell: /home/ffmpeg-2.0.1-64bit-static/ffmpeg -i rtmp://localhost:1935/livetv/2ch5h264 -vn -ar 44100 -ac 2 -ab 128k -f wav -ss 00:00:00 -t 7200...
Jon Skeet
people
quotationmark

It sounds like the problem is that ffmpeg is writing log information, and you're not reading it in the Java code. There will be a small buffer between the processes, and when that buffer fills up, ffmpeg will block when it tries to write... more 1/22/2014 1:20:49 PM

people