for science project I'm direct messaging twitter with twitter4j lib and android 2.1 but app immediately crashes
I'm a complete beginner in java but I need to make this application to send commands over twitter. I'm using the twitter4J library and android 2.1. I finally have my code with no errors but when the app starts in the emulator, it immediately crashes. Has anyone done this before?
CODE(main file):
package edu.shs.SHSSRP;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import edu.shs.SHSSRP.TwitterTest;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Button;
public class SHSSRP extends Activity {
/** Called when the activity is first created. */
WebView webview;
Button Forward;
Button Backward;
Button Left;
Button Right;
TwitterTest TwitTest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Twitter twitter = new TwitterFactory().getInstance("SHSSRP","123ABC1234");
try {
Status status = twitter.updateStatus("HELLO WORLD!");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* Forward = (Button) findViewById(R.id.Forward);
Backward = (Button) findViewById(R.id.Backward);
Left = (Button) findViewById(R.id.Left);
Right = (Button) findViewById(R.id.Right);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com");
TwitTest.runTest();
*/
}
}
CODE(function)
package edu.shs.SHSSRP;
import twitter4j.DirectMessage;
import twitter4j.ResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import android.app.Activity;
import twitter4j.*;
public class TwitterTest extends Activity
{
public void runTest()
{
// The factory instance is re-usable and thread safe.
Twitter twitter = new TwitterFactory().getInstance("SenderID","SenderPass");
try {
twitter.sendDirectMessage("ReceiverID", "HelloWorld");
} catch (TwitterException e) {
e.printStackTrace();
}
}
}
CODE(manifest) simply add the uses permission for interet
CODE(layout)
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/Forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/webview"
android:text="@string/Forward" />
<Button
android:id="@+id/Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Forward"
android:layout_alignParentLeft="true"
android:text="@string/Left" />
<Button
android:id="@+id/Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/Forward"
android:text="@string/Right" />
<Button
android:id="@+id/Backward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@id/Right"
android:text="@string/Backward" />
thank you in advance,
Matt
Asked by: Alissa281 | Posted: 25-01-2022
Answer 1
In your AndroidManifest.xml file you need to specify that your application will connect to the internet.
Paste this just above the <application>
node:
<uses-permission android:name="android.permission.INTERNET"/>
Answered by: Anna436 | Posted: 26-02-2022
Answer 2
As the other folk have indicated, posting the stack trace would be a big help.
That being said, you might also consider switching to JTwitter. I know from first-hand experience that it works on Android, though I tend to remove the duplicate org.json
classes that JTwitter has in its published JAR.
Similar questions
java - Internet on android, causing twitter4j exception?
I'm experimenting with twitter4j on android (new to both) coded up a simple process in java just to test it out. It downloads a users timeline and prints to screen.
I modify the code for android, but I get a TwitterException when i try to download the user timeline. I checked out the debugger and the exception is null; no information given. I've also added the Internet permission to the android manifest on previous...
Android Twitter4j Error
I am getting following error while updating my twitter status from java code in android using Twitter4J .
Any help will be appreciated.....
09-18 11:34:50.476: WARN/System.err(755): TwitterException{exceptionCode=[15bb6564-00e4d61f], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a855f3e889507)}
09-18 11:34:50.476: WARN/System.err(755): ...
Android Twitter4j
I want to create a application where user can login with twitter account and whatever activity he does (depending on other cases) should be tweeted.
Now since twitter has removed basic authentication how to achieve this ????
Any help will be appreciated
android - SignPost or Twitter4j for Sign-in with Twitter (OAuth)?
I read a lot about signpost, and then went back to Twitter4J with which I have created my twitter applications when OAuth wasn't necessary.
I am now confused whether I should use signpost or Twitter4J's method of OAuth authentication.
I have read that Twitter4J itself uses signpost for OAuth, still am not sure about the choice that I should make.
Kindly assist.
Thanks a lot!
android - pin in twitter4j
How can I get the pin for the twitter 4j ?
accessToken = twitter.getOAuthAccessToken(requestToken, pin);
please help..!
twitter - Android Twitter4j Automatic updates
We are integrating twitter to my android application.
We are using Twitter4j library and are able to read the tweets by gettimeline Apis.
Anyone aware of any APIs(From twitter or written in library) which will directly invoke a call back function in my application.
My intention is to avoid periodic api calls in application.
Can anyone help?
Regards,
Dhanesh
api - Android-Twitter Twitter4j dialoge "Sign Up" link not working
I have an app that basically allows you to tweet,
After logging in via the twitter4j dialoge you can go ahead and proceed to tweet via the application etc.
The problem is, when the dialoge appears showing the twitter website to logging in, the link "sign up" or "forgot password" doest work....
Ive searched around but cannot find any explination?
If any code is requires please ask,
Thank you in advan...
Android Twitter4j getting error while retweet or send message
I am making an app for twitter integration using Twitter4j API.
Right now my problem is,
when i tried to make retweet or send direct messages like:
twitter.retweetStatus(sid);
twitter.sendDirectMessage(uid, msg);
i got the following error:
> 08-20 11:11:17.409: WARN/System.err(233): 403:The request is
> understood, but it has been refused. An accompany...
java - Twitter4J timeline in Android ListView
I am using Twitter4J to get a public timeline from twitter. I want to display the data in a ListView but I don't know what to do with the List<Status> type I get from twitter4j. How do I get that into an Array so that I can use it with my ArrayAdapter.
If I am going about this completely wrong I apologize. I am new to Java and Android.
EDIT:
To be more clear I am trying to display...
android - how to oauth twitter with Twitter4J api
I want to authenticate twitter with Twitter4j api but it gives following error:
09-13 12:12:09.223: WARN/System.err(677): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.
09-13 12:12:09.233: WARN/System.err(677): at oauth.signpost.basic.DefaultOAuthProvider.retri...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android