Hi, 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