Browsing 7239 questions and answers with Jon Skeet

Replace an extra number from date

I have OCR extracted date string due to image quality second slash of date comes as 1, i.e. date comes as 23/0212014 where 1 before year should be / actually. I have tried to...
Jon Skeet
people
quotationmark

DateTime.TryParseExact works fine for me: using System; using System.Globalization; class Test { static void Main() { string text = "23/0212014"; DateTime result; if (DateTime.TryParseExact(text,... more 4/7/2014 8:19:16 AM

people

ClassCastException in android database

I have a MainActivity whose onCreate is //called when activity first created @Override protected void onCreate(Bundle savedInstanceState) { ...
Jon Skeet
people
quotationmark

Well this looks like it's probably the problem: delegate = (AsynResponse) context; You're casting the context variable to AsynResponse, and that context variable comes from here: new SQLLiteDbHelper(MainActivity.this, ...) So it... more 4/7/2014 7:22:43 AM

people

Non Invocable member iTextSharp.text.font cannot be used like a method

iTextSharp.text.Font fontbold = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10); iTextSharp.text.Font font5 =...
Jon Skeet
people
quotationmark

Well I suspect that Font is a property rather than a method, in which case you'd just want: p.Font = font5; pr.Font = fontbold; That would certainly be more idiomatic C#. I haven't used iTextSharp, so I could be wrong, but that would be... more 4/7/2014 6:19:33 AM

people

How to use string as variable name in c#

am having a viewstate which pertains value like: string temp; ViewState["temp"] = dc.ColumnName.ToString(); This returns weekdays like: Monday,tuesday,wednesday etc Now am...
Jon Skeet
people
quotationmark

No, you can't. At least not without reflection, and you shouldn't be using reflection here. Variables in C# are a compile-time concept. (Even with reflection, it'll only work for fields, not for local variables.) If you want a collection... more 4/7/2014 6:16:17 AM

people

Different users select same key in java hashmap at same time will it be thread safe?

I have a function working in java such that HashMap has a store of key as String and value as ArrayList. So my quetion is when different user login at the same time and they try...
Jon Skeet
people
quotationmark

Regardless of whether you're using the same key, HashMap simply isn't thread safe for any writing: Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads... more 4/7/2014 5:58:26 AM

people

Java poker deck all same cards

I've created a deck Card[52] theDeck and it seems to only contain Kings of Spades. I don't think anything wrong with the constructor, but I'm new to java, so I might be...
Jon Skeet
people
quotationmark

You've got three loops, and your inner loop goes through the whole range of the deck - and assigns a card to it which doesn't depend on the index: for (int i = 0; i < theDeck.length; i++) { theDeck[i] = new Card(s,v); } So for... more 4/7/2014 5:52:46 AM

people

Java When outputting String and method return, why does method return output first?

In the code below, if the string "Mult" comes before the test1(4) method call, why does the method output before the string? And why does it bounce form outputting the first part...
Jon Skeet
people
quotationmark

In the code below, if the string "Mult" comes before the test1(4) method call, why does the method output before the string? Because you're calling the method before you're calling System.out.println with the "Mult:" part. Basically,... more 4/6/2014 9:00:02 PM

people

Why an identifier is expected while declaring a delegate?

When we create a delegate in C#, to point a function with a definite signature (parameter set), it asks us to specify the identifier also for each type. public delegate void...
Jon Skeet
people
quotationmark

It can make a difference at the point of invocation. For example: using System; class Test { delegate void Foo(int x, int y); static void Main() { Foo foo = (x, y) => Console.WriteLine("x={0}, y={1}", x, y); ... more 4/6/2014 8:41:45 PM

people

Unable to write anything to file

I am trying to write to file try { PrintWriter fileout = new PrintWriter("./src/javaapplication1/test.dat"); for(int i=0;i<10;i++) { fileout.println(i); ...
Jon Skeet
people
quotationmark

You haven't closed the writer. It's almost certainly just buffered all the data. You should always close IO streams etc. If you're using Java 7+, you can use a try-with-resources statement: try (PrintWriter fileout = new... more 4/6/2014 8:10:19 AM

people

String was not recognized as a valid datetime in shamsi date fa ir

I use shamsi date in my program and save it in sqllite date table. I use LINQ to save before save convert my date....
Jon Skeet
people
quotationmark

Currently I suspect you're parsing the date as a Gregorian date - which will fail if you try to input a date with a month of 2 but a day of 30 or 31 (or a day of 28 in a non-leap year). DateTime itself assumes the Gregorian calendar, but... more 4/6/2014 8:03:08 AM

people