Categories
discuss

Parse RSS pubDate to Date object in java

How can I parse a pubDate from a RSS feed to a Date object in java.

The format in the RSS feed: Sat, 24 Apr 2010 14:01:00 GMT

What I have at the moment:

DateFormat dateFormat = DateFormat.getInstance();
Date pubDate = dateFormat.parse(item.getPubDate().getText());

But this code throws an ParseException with the message Unparseable date

Answer

You can define the date format you are trying to parse, using the class SimpleDateFormat:

DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
Date date = formatter.parse("Sat, 24 Apr 2010 14:01:00 GMT");

Additionally, for non-English Locale‘s, be sure to use the following when parsing dates in English:

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
Categories
discuss

How do they do it? Dialogs over home screen

I’m writing an Android application and I would like to place a dialog or view over the home screen so that a user can enter text without jumping into my full application. I can’t seem to get this to work. If I present a dialog (even in a transparent activity), my application launches.

If you don’t know what I’m talking about, take a look at the Facebook widget. I want to replicate a similar behavior to the clicking on the “What’s on your mind?” box.

Thanks for any help in advance!

-Brian

Answer

My problem was that the application always launched to display the dialog.

To solve this, I set the activity lauch mode to singleInstance in the manifest. Now it shows the dialog over the home screen!

Categories
discuss

Strings don’t seem to be equal in Java on Android, even though they print the same

I’ve got a problem that I’m rather confused about. I have the following lines of code in my android application:

System.out.println(CurrentNode.getNodeName().toString());
if (CurrentNode.getNodeName().toString() == "start") {
    System.out.println("Yes it does!");
} else {
    System.out.println("No it doesnt");
}

When I look at the output of the first println statement it shows up in LogCat as “start” (without the quotes obviously). But then when the if statement executes it goes to the else statement and prints “No it doesn’t”.

I wondered if the name of the node might have some kind of non-printing character in it, so I’ve checked the length of the string coming from getNodeName() and it is 5 characters long, as you would expect.

Has anyone got any idea what’s going on here?

Answer

Use String’s equals method to compare Strings. The == operator will just compare object references.

if ( CurrentNode.getNodeName().toString().equals("start") ) {
   ...
Categories
discuss

Uncaught Error: SECURITY_ERR: DOM Exception 18 when I try to set a cookie

I get the following error in Chrome’s developer tools window when I try to set a cookie using this jQuery plugin:

Uncaught Error: SECURITY_ERR: DOM Exception 18

What does this error mean and how can I fix it? I get the same error when I use this jQuery plugin.

Answer

You’re most likely using this on a local file over the file:// URI scheme, which cannot have cookies set. Put it on a local server so you can use http://localhost.

Categories
discuss

In the Android emulator, is it possible to notice vibration effects?

Quite a simple question. Is it possible to notice vibrations in the Android emulator?

Answer

I guess you want to know if vibration happened ? If that is so then look into the logcat in the emulator for the vibration message

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..