My android app is supposed to go through twitter using twitter4j libraries, and return a bunch of tweets with the keyword you search. The app doesn't crash like it used to, but it is also bugged somehow to where it doesn't print out anything.
Here is the code:
package com.SMARTlab.twitterapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import twitter4j.*;
public class TwitterApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button search = (Button)findViewById(R.id.search_button);
search.setOnClickListener(search_OnClickListener);
}
public void onClick(View v)
{
switch (v.getId())
{
case R.id.search_button:
Intent i = new Intent开发者_如何学C(this, com.SMARTlab.twitterapp.TwitterApp.class);
startActivity(i);
break;
}
}
@SuppressWarnings("deprecation")
private Button.OnClickListener search_OnClickListener = new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
Twitter t = new TwitterFactory().getInstance();
EditText ed = (EditText)findViewById(R.id.search_box);
TextView txt = (TextView)findViewById(R.id.text_box);
Query q = new Query(ed.getText().toString());
QueryResult res = null;
try
{
res = t.search(q);
txt.setText("");
}
catch(TwitterException ex) {System.out.println(ex.toString());}
for (Tweet tw : res.getTweets())
{
try
{
long[] id = t.getRetweetedByIDs(tw.getId()).getIDs();
for (int x = 0; x < id.length; x++)
queryRank += 1;
} catch(TwitterException te) {}
if (evaluateRank(queryRank))
{
txt.append((String)"[" + tw.getFromUser() + "] " + tw.getText() + "\n");
}
}
}
int queryRank = 0;
private boolean evaluateRank(int rank)
{
if (rank > 10)
return true;
return false;
}
};
}
Here is the AndroidMnifest.xml file's contents just in case you need it:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SMARTlab.twitterapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TwitterApp"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And here is the LogCat:
06-13 09:35:42.036: DEBUG/AndroidRuntime(425): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-13 09:35:42.036: DEBUG/AndroidRuntime(425): CheckJNI is ON
06-13 09:35:42.255: DEBUG/AndroidRuntime(425): --- registering native functions ---
06-13 09:35:43.076: DEBUG/AndroidRuntime(425): Shutting down VM
06-13 09:35:43.076: DEBUG/dalvikvm(425): Debugger has detached; object registry had 1 entries
06-13 09:35:43.116: INFO/AndroidRuntime(425): NOTE: attach of thread 'Binder Thread #3' failed
06-13 09:35:43.625: DEBUG/AndroidRuntime(433): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-13 09:35:43.635: DEBUG/AndroidRuntime(433): CheckJNI is ON
06-13 09:35:43.855: DEBUG/AndroidRuntime(433): --- registering native functions ---
06-13 09:35:44.645: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.SMARTlab.twitterapp/.TwitterApp }
06-13 09:35:44.705: INFO/ActivityManager(59): Start proc com.SMARTlab.twitterapp for activity com.SMARTlab.twitterapp/.TwitterApp: pid=439 uid=10040 gids={}
06-13 09:35:44.755: DEBUG/AndroidRuntime(433): Shutting down VM
06-13 09:35:44.765: DEBUG/dalvikvm(433): Debugger has detached; object registry had 1 entries
06-13 09:35:44.825: INFO/AndroidRuntime(433): NOTE: attach of thread 'Binder Thread #3' failed
06-13 09:35:46.026: INFO/ActivityManager(59): Displayed activity com.SMARTlab.twitterapp/.TwitterApp: 1329 ms (total 1329 ms)
06-13 09:35:51.135: DEBUG/dalvikvm(123): GC_EXPLICIT freed 230 objects / 9920 bytes in 75ms
06-13 09:36:51.735: WARN/KeyCharacterMap(439): No keyboard for id 0
06-13 09:36:51.735: WARN/KeyCharacterMap(439): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-13 09:36:57.306: INFO/System.out(439): Permission deniedRelevant discussions can be on the Internet at:
06-13 09:36:57.306: INFO/System.out(439): http://www.google.co.jp/search?q=d35baff5 or
06-13 09:36:57.316: INFO/System.out(439): http://www.google.co.jp/search?q=08a954d5
06-13 09:36:57.316: INFO/System.out(439): TwitterException{exceptionCode=[d35baff5-08a954d5 43208640-0c814192], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.3}
06-13 09:36:57.316: DEBUG/AndroidRuntime(439): Shutting down VM
06-13 09:36:57.326: WARN/dalvikvm(439): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): FATAL EXCEPTION: main
06-13 09:36:57.336: ERROR/AndroidRuntime(439): java.lang.NullPointerException
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at com.SMARTlab.twitterapp.TwitterApp$1.onClick(TwitterApp.java:50)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.view.View.performClick(View.java:2408)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.view.View$PerformClick.run(View.java:8816)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.os.Handler.handleCallback(Handler.java:587)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.os.Handler.dispatchMessage(Handler.java:92)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.os.Looper.loop(Looper.java:123)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at java.lang.reflect.Method.invoke(Method.java:521)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-13 09:36:57.336: ERROR/AndroidRuntime(439): at dalvik.system.NativeStart.main(Native Method)
06-13 09:36:57.356: WARN/ActivityManager(59): Force finishing activity com.SMARTlab.twitterapp/.TwitterApp
06-13 09:36:57.875: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45050718 com.SMARTlab.twitterapp/.TwitterApp}
06-13 09:37:00.995: INFO/Process(439): Sending signal. PID: 439 SIG: 9
06-13 09:37:01.015: INFO/ActivityManager(59): Process com.SMARTlab.twitterapp (pid 439) has died.
06-13 09:37:01.015: INFO/WindowManager(59): WIN DEATH: Window{4503edf8 com.SMARTlab.twitterapp/com.SMARTlab.twitterapp.TwitterApp paused=false}
06-13 09:37:01.085: WARN/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 439 uid 10040
Please help! Thank you in advance for your answers! :)
You shouldn't just catch NullPointerExceptions
and TwitterExceptions
then do nothing in your catch block. The chances are that your code is failing and all you are effectively doing is preventing the cause from being reported. Remove your try/catch
blocks which are catching and suppressing these exceptions and then work out what is causing them to be thrown. I would guess that once you fix your the root causes of these exceptions then things may start working.
精彩评论