Jump to content

The code in the book "Learning Android" does not run

dineshb's Photo
Posted Apr 02 2011 05:56 AM
10345 Views

Hi,

The sample app given under the heading "Threading in Android" in the book "Learning Android" crashes whenever it tries to update the "twitter" status of the user.

The stack trace of the error is given below:

04-02 14:37:20.295: ERROR/AndroidRuntime(370): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception

04-02 14:37:20.315: ERROR/AndroidRuntime(370): java.lang.RuntimeException: An error occured while executing doInBackground()

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at android.os.AsyncTask$3.done(AsyncTask.java:200)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.lang.Thread.run(Thread.java:1096)

04-02 14:37:20.315: ERROR/AndroidRuntime(370): Caused by: java.lang.IllegalArgumentException

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.Date.parse(Date.java:447)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.Date.<init>(Date.java:157)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at winterwell.jtwitter.Twitter$Status.<init>(Twitter.java:614)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:3073)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:3003)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at com.marakana.yamba.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:44)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at com.marakana.yamba.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:1)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at android.os.AsyncTask$2.call(AsyncTask.java:185)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

04-02 14:37:20.315: ERROR/AndroidRuntime(370):     ... 4 more


Could anyone please suggest the solution for this problem?

Tags:
1 Subscribe


13 Replies

+ 2
  Marko Gargenta - Marakana's Photo
Posted Apr 03 2011 06:40 AM

You are using the JTwitter library downloaded from http://winterwell.co...e/jtwitter.php. This library has a problem with how it parses Java Date object. I have fixed this problem and released an alternative JTwitter library available at http://marakana.com/...itter-yamba.jar and attached to this post. I also notified original authors.

There's a note in the book on page 60 explaining this as well. Hope this helps.
Marko

Learning Android

Learn more about this topic from Learning Android.

If you're new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. This gentle introduction shows you how to use Android's basic building blocks to develop user interfaces, store data, and more. You'll build an example application throughout the course of book, adding new features with each chapter. You'll also build your own toolbox of code patterns that will help you program any type of Android application with ease.

See what you'll learn

 : Apr 03 2011 08:05 AM
On replacing the jar, the code executed flawlessly. Many thanks!!! :)
 : Apr 08 2011 11:03 AM
I have downloaded the specified JAR file but it still gives the message "Failed to post".

It shows this in the logcat

04-09 00:20:24.588: WARN/System.err(312): winterwell.jtwitter.TwitterException$E401: Unauthorized http://yamba.marakana.com/api/statuses/update.json (yogeshupside)
04-09 00:20:24.608: WARN/System.err(312):     at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:125)
04-09 00:20:24.608: WARN/System.err(312):     at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:219)
04-09 00:20:24.628: WARN/System.err(312):     at winterwell.jtwitter.Twitter.post(Twitter.java:1944)
04-09 00:20:24.628: WARN/System.err(312):     at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2555)
04-09 00:20:24.648: WARN/System.err(312):     at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2502)
04-09 00:20:24.648: WARN/System.err(312):     at com.marakana.yamba1.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:60)
04-09 00:20:24.669: WARN/System.err(312):     at com.marakana.yamba1.StatusActivity$PostToTwitter.doInBackground(StatusActivity.java:1)
04-09 00:20:24.669: WARN/System.err(312):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-09 00:20:24.688: WARN/System.err(312):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-09 00:20:24.688: WARN/System.err(312):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-09 00:20:24.708: WARN/System.err(312):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-09 00:20:24.708: WARN/System.err(312):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-09 00:20:24.728: WARN/System.err(312):     at java.lang.Thread.run(Thread.java:1096)


Could you please help.
0
  meinsatiable's Photo
Posted Apr 08 2011 11:53 AM

It seems that the account with the username "student" has been removed.

@Marko - ??? :(
+ 1
  yogesh.agarwal's Photo
Posted Apr 08 2011 09:57 PM

meinsatiable - I have already replaced "student" with my actual twitter account details...but it didn't work.
0
  Saurav Malik's Photo
Posted Apr 09 2011 10:03 AM

Hi Yogesh, i am also facing the same problem. It is also showing to me a message, like; "Failed to post".

Could you fix it and not or do u have any idea to correct it?

Actually i had recently read somewhere on site that Twitter has stopped to accept the authorization in this manner in which this book refers. Now twitter accepts the twitts from "OAuth". Do you have any idea of it? If yes, so please share.

Thanks
Saurabh
-1
  meinsatiable's Photo
Posted Apr 11 2011 07:14 AM

I tried with "student" and it works.
0
  yogesh.agarwal's Photo
Posted Apr 11 2011 11:03 AM

Saurabh - it didnt work for me.
0
  BorisB's Photo
Posted Dec 24 2011 03:40 PM

I completed chapter 6 in Learning Android and I am also getting "Failed to post" message, was this issue resolved.

Thank you.
0
  EKRu's Photo
Posted Jan 06 2012 07:16 AM

It didn't worked for me when I tried to post the default text "Please enter your 140-character status". When I entered any text it worked OK
+ 1
  h_sedghy's Photo
Posted Apr 18 2012 01:58 AM

Hi
I have a problem.
I downloaded jtwitter-yamba.jar from the link you wrote and also I updated StatusActivity.java like page no 58.
When I run the app it is Ok but when I click on the button and it calls below line
twitter.setStatus(editText.getText().toString()); //
I face the message of forececlose.
Also I remarked two below lines
// twitter = new Twitter("student", "password"); //
// twitter.setAPIRootUrl("http://yamba.marakana.com/api")

because it cause the same problem in starting the app.
I have this in LogCat:
Android Runtime at com.marakana.yamba.StatusActivity.onClick
Android Runtime :java.lang.NoClassDefFoundError: winterwell.jtwitter.Twitter

How can I solve the problem?
0
  remijnj's Photo
Posted Jun 17 2012 07:33 AM

Hi h_sedghy,

I think you need are missing the .jar from the apk You can go right-click on your project, select Properties and go to Java build path. In there go to the tab Order and Export and check jtwiiter-yamba.jar. Without it it did not work for me either.
0
  Vicky3's Photo
Posted Jul 04 2012 12:22 AM

I replaced the jtwitter library with the new one and I removed the hardcoded lines

// twitter = new Twitter("student", "password");
// twitter.setAPIRootUrl("http://yamba.marakana.com/api");

Now it works fine for student ID as well as personally created Ids

cheers
Vicky