0

Hi I am getting the friend list from twitter now i want to tweet to particular user selected from the list. Any code snippet would be appreciated. Here is i am getting NullPointerException on twitter.sendmessage("id of user","msg")

private void tweet(){
    setTitle("Tweet");
    AlertDialog.Builder inputDialog;
    inputDialog = new AlertDialog.Builder(MainActivity.this);
    inputDialog.setTitle("Enter Tweet");
    et_input = new EditText(MainActivity.this);
    et_input.setWidth(250);
    et_input.setHeight(30);
    inputDialog.setView(et_input);
    inputDialog.setPositiveButton("Ok",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        txt_tweet= et_input.getText().toString();
        System.out.println("String what i have type "+txt_tweet);
            try{
               twitter.sendMessage("testsynapse1", txt_tweet);
                Toast.makeText(MainActivity.this,
                    "Tweet Successful", Toast.LENGTH_LONG).show();
            }
            catch (TwitterException e) {
                // TODO: handle exception
                e.getMessage();
            }
        }
    });
    inputDialog.setNegativeButton("Cancle",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        }
    });
    inputDialog.show();
}
Shruti
  • 1
  • 13
  • 55
  • 95
arun jagga
  • 87
  • 1
  • 11
  • `Any code snippet would be appericiated.` - likewise to you. Could you provide an outline of your current code? – Aske B. Sep 05 '12 at 10:26
  • Look here: [ask]. **1.** You'll give answerers an insight of your research so they don't have to do it themselves. If you ask without context, you should accept that you're only asking the few people who have done this recently and therefore remember it all, plus are willing provide the time and effort into providing an answer that will most likely be edited multiple times since you didn't provide in what context you want this to be implemented. **2.** If you provide code, people will be able to understand the problem faster, and they'll also be able to do their own research based on that. – Aske B. Sep 05 '12 at 10:42
  • AskeB thanx for u r kind info i m asking to who already implement like expertese on this subject – arun jagga Sep 05 '12 at 10:47
  • Well, I'm sure there's plenty of people here who are either willing to help you with a solution or have experience with the matter, after all it's not a new technology released today. What I'm saying is, you will most likely not be getting the answers you need if you ask this way. – Aske B. Sep 05 '12 at 10:50
  • Maybe this question could help: http://stackoverflow.com/questions/2077008/android-intent-for-twitter-application – Aske B. Sep 05 '12 at 11:07
  • What type is that `twitter`-variable you call the `sendMessage()`-method on? Is it [Twitter4j](http://twitter4j.org)? [JTwitter](http://www.winterwell.com/software/jtwitter.php)? – Aske B. Sep 05 '12 at 11:14

1 Answers1

1

Do you know the username of particular user? If yes,

Then do like this:

String tweetToPost="@"+userName+"%20"+"your message"; 

postTweet(tweetToPost); 


public void postTweet(String str){
  String url="https://twitter.com/intent/tweet?text="+str.replace(" ","%20");

  WebView wv=new WebView(this);
        wv.loadUrl(url);
        setContentView(wv);
        wv.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
            }


        });


}

I don't know if it works or not. But generally tweets to a specific user in Twitter are in the same format.

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109