MalformedException when sending status message - Please Respond

Forums » Android - Learning Android book > MalformedException when sending status message - Ple...
February 9, 2012 3:44:00 AM PST (one year ago). Seen 884 times. 3 replies.
Photo Vikam Boidapu
Project Manager
EA
Member since Jan 31, 2012
Forum Posts: 3
Hi

when I am following the course part 3 video:
I am getting the following error
Could some one help me why I am getting this error.


Source code : SuperTweetActivity.java
Code:

package com.test;

import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SuperTweetActivity extends Activity implements OnClickListener {

private static final String TAG = "SuperTweet";
EditText editStatus;
Button buttonUpdate;
Twitter twitter;

static final int DIALOG_ID = 47;

// Shared Preference
// SharedPreferences prefs;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Log.d(TAG, "onCreated called for you");

try {
// Debug.startMethodTracing("supertweet.trace");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

setContentView(R.layout.status);

editStatus = (EditText) findViewById(R.id.editStatus);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);

buttonUpdate.setOnClickListener(this);
}

@Override
protected void onStop() {
try {
// TODO Auto-generated method stub
super.onStop();
// Debug.stopMethodTracing();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void onClick(View v) {
try {
String status = editStatus.getText().toString();
showDialog(DIALOG_ID);
new PostToTwitter().execute(status);
Log.d(TAG, "onClicked");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

// Menu Stuff

// Called first time user clicks on the menu button
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;// super.onCreateOptionsMenu(menu);
}

@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {

case DIALOG_ID: {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle(SuperTweetActivity.this
.getString(R.string.msgPostingToTwitter));
dialog.setMessage(SuperTweetActivity.this
.getString(R.string.msgPleaseWaitWhilePosting));
dialog.setIndeterminate(true);
dialog.setCancelable(true);

return dialog;
}

}

return null;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.itemPrefs:
startActivity(new Intent(this, PrefsActivity.class));
break;
case R.id.itemServiceStart:
startService(new Intent(this, UpdaterService.class));
break;
case R.id.itemStopService:
stopService(new Intent(this, UpdaterService.class));
break;

}
// TODO Auto-generated method stub
return true;
}

// Asynchronously posts to twitter
class PostToTwitter extends AsyncTask<String, Integer, String> {

// Called to initiate the background activity
@Override
protected String doInBackground(String... status) {
try {
Log.d(TAG, "Camee..in do in background");
((SuperTweetApplication) SuperTweetActivity.this
.getApplication()).getTwitter().setStatus(status[0]);
return "Sucessfull";
// return (app.getTwitter().getStatus()).text;

} catch (TwitterException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
return "Failed to post";
}

}

// Called when there's a status to be updated
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
// Not used in this case
}

// Called once the background activity has completed
@Override
protected void onPostExecute(String result) {
Log.d(TAG, "%s:"+result);
Toast.makeText(SuperTweetActivity.this, result, Toast.LENGTH_LONG)
.show();
dismissDialog(DIALOG_ID);
}
}

// TextWatcher methods
/*
* public void afterTextChanged(Editable statusText) { // <7> int count =
* 140 - statusText.length(); // <8>
* textCount.setText(Integer.toString(count));
* textCount.setTextColor(Color.GREEN); // <9> if (count < 10)
* textCount.setTextColor(Color.YELLOW); if (count < 0)
* textCount.setTextColor(Color.RED); }
*/
public void beforeTextChanged(CharSequence s, int start, int count,
int after) { // <10>
}

public void onTextChanged(CharSequence s, int start, int before, int count) { // <11>
}

}



Log file:
Code:


02-09 16:22:05.660: D/SuperTweet(565): onClicked
02-09 16:22:05.670: D/SuperTweet(565): Camee..in do in background
02-09 16:22:06.270: E/SuperTweet(565): winterwell.jtwitter.TwitterException: java.net.MalformedURLException: Protocol not found: /statuses/update.json
02-09 16:22:06.270: W/System.err(565): winterwell.jtwitter.TwitterException: java.net.MalformedURLException: Protocol not found: /statuses/update.json
02-09 16:22:06.270: W/System.err(565): at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:223)
02-09 16:22:06.280: W/System.err(565): at winterwell.jtwitter.Twitter.post(Twitter.java:1944)
02-09 16:22:06.280: W/System.err(565): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2555)
02-09 16:22:06.280: W/System.err(565): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2502)
02-09 16:22:06.280: W/System.err(565): at winterwell.jtwitter.Twitter.setStatus(Twitter.java:2274)
02-09 16:22:06.280: W/System.err(565): at com.test.SuperTweetActivity$PostToTwitter.doInBackground(SuperTweetActivity.java:163)
02-09 16:22:06.280: W/System.err(565): at com.test.SuperTweetActivity$PostToTwitter.doInBackground(SuperTweetActivity.java:1)
02-09 16:22:06.280: W/System.err(565): at android.os.AsyncTask$2.call(AsyncTask.java:264)
02-09 16:22:06.290: W/System.err(565): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-09 16:22:06.290: W/System.err(565): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-09 16:22:06.290: W/System.err(565): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
02-09 16:22:06.290: W/System.err(565): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-09 16:22:06.330: W/System.err(565): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-09 16:22:06.351: W/System.err(565): at java.lang.Thread.run(Thread.java:856)
02-09 16:22:06.351: W/System.err(565): Caused by: java.net.MalformedURLException: Protocol not found: /statuses/update.json
02-09 16:22:06.360: W/System.err(565): at java.net.URL.<init>(URL.java:178)
02-09 16:22:06.360: W/System.err(565): at java.net.URL.<init>(URL.java:127)
02-09 16:22:06.360: W/System.err(565): at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:196)


Edited 4 times. Last edit by Vikam Boidapu on Feb 9, 2012 at 3:44:00 AM (about one year ago).
February 9, 2012 10:53:21 PM PST (one year ago)
Photo Vikam Boidapu
Project Manager
EA
Member since Jan 31, 2012
Forum Posts: 3
Hi Guys,

I have finally solved this issue.

The error is coming at :

Code:
String username=prefs.getString("username","");
String password=prefs.getString("password","");

Before :
String server=prefs.getString("serverurl"," ");

The url has to be formatted when retrieving from the preferences.

After Solution :
String server=prefs.getString("serverurl","http://yamba.marakana.com/api");


Thanks,
-Vikram
February 13, 2012 4:36:49 PM PST (one year ago)
Photo Marko Gargenta
@MarkoGargenta
Marakana, Inc.
Member since Jan 19, 2007
Location: San Francisco
Forum Posts: 227
Glad it worked out!
November 17, 2012 10:21:00 PM PST (26 weeks ago)
Photo Techi Coder
Self
Member since Nov 16, 2012
Forum Posts: 1
Thanks Vikam.