它一直崩溃。我认为这与意图有关。请帮忙。
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(this, com.SMARTlab.twitterapp.TwitterApp.class);
startActivity(i);
break;
}
}
@SuppressWarnings("deprecation")
private Button.OnClickListener search_OnClickListener = new Button.OnClickListener()
{
int queryRank = 0;
private boolean evaluateRank(int rank)
{
if (rank > 10)
return true;
return false;
}
@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");
}
}
}
};
}
这是LogCat。
06-10 12:44:08.145: DEBUG/AndroidRuntime(416): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-10 12:44:08.145: DEBUG/AndroidRuntime(416): CheckJNI is ON
06-10 12:44:08.365: DEBUG/AndroidRuntime(416): --- registering native functions ---
06-10 12:44:09.285: DEBUG/dalvikvm(253): GC_EXPLICIT freed 176 objects / 8856 bytes in 55ms
06-10 12:44:10.446: DEBUG/PackageParser(59): Scanning package: /data/app/vmdl44188.tmp
06-10 12:44:10.647: INFO/PackageManager(59): Removing non-system package:com.SMARTlab.twitter
06-10 12:44:10.647: INFO/ActivityManager(59): Force stopping package com.SMARTlab.twitter uid=10039
06-10 12:44:11.455: DEBUG/PackageManager(59): Scanning package com.SMARTlab.twitter
06-10 12:44:11.465: INFO/PackageManager(59): Package com.SMARTlab.twitter codePath changed from /data/app/com.SMARTlab.twitter-2.apk to /data/app/com.SMARTlab.twitter-1.apk; Retaining data and using new
06-10 12:44:11.475: INFO/PackageManager(59): /data/app/com.SMARTlab.twitter-1.apk changed; unpacking
06-10 12:44:11.556: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/com.SMARTlab.twitter-1.apk' ---
06-10 12:44:14.765: DEBUG/dalvikvm(423): DexOpt: load 105ms, verify 473ms, opt 23ms
06-10 12:44:16.048: DEBUG/installd(35): DexInv: --- END '/data/app/com.SMARTlab.twitter-1.apk' (success) ---
06-10 12:44:16.246: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 9625 objects / 558632 bytes in 176ms
06-10 12:44:16.246: WARN/PackageManager(59): Code path for pkg : com.SMARTlab.twitter changing from /data/app/com.SMARTlab.twitter-2.apk to /data/app/com.SMARTlab.twitter-1.apk
06-10 12:44:16.246: WARN/PackageManager(59): Resource path for pkg : com.SMARTlab.twitter changing from /data/app/com.SMARTlab.twitter-2.apk to /data/app/com.SMARTlab.twitter-1.apk
06-10 12:44:16.246: DEBUG/PackageManager(59): Activities: com.SMARTlab.twitter.Twitter
06-10 12:44:16.288: INFO/ActivityManager(59): Force stopping package com.SMARTlab.twitter uid=10039
06-10 12:44:17.117: INFO/installd(35): move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
06-10 12:44:17.117: DEBUG/PackageManager(59): New package installed in /data/app/com.SMARTlab.twitter-1.apk
06-10 12:44:17.975: INFO/ActivityManager(59): Force stopping package com.SMARTlab.twitter uid=10039
06-10 12:44:18.065: DEBUG/dalvikvm(124): GC_EXPLICIT freed 910 objects / 48976 bytes in 67ms
06-10 12:44:18.166: DEBUG/dalvikvm(151): GC_EXPLICIT freed 1750 objects / 89136 bytes in 89ms
06-10 12:44:18.456: WARN/RecognitionManagerService(59): no available voice recognition services found
06-10 12:44:18.775: DEBUG/dalvikvm(59): GC_EXPLICIT freed 5654 objects / 334424 bytes in 261ms
06-10 12:44:19.115: INFO/installd(35): unlink /data/dalvik-cache/data@[email protected]@classes.dex
06-10 12:44:19.196: DEBUG/AndroidRuntime(416): Shutting down VM
06-10 12:44:19.216: DEBUG/dalvikvm(416): Debugger has detached; object registry had 1 entries
06-10 12:44:19.236: INFO/AndroidRuntime(416): NOTE: attach of thread 'Binder Thread #3' failed
06-10 12:44:19.955: DEBUG/AndroidRuntime(429): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-10 12:44:19.955: DEBUG/AndroidRuntime(429): CheckJNI is ON
06-10 12:44:20.175: DEBUG/AndroidRuntime(429): --- registering native functions ---
06-10 12:44:21.025: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.SMARTlab.twitter/.Twitter }
06-10 12:44:21.135: DEBUG/AndroidRuntime(429): Shutting down VM
06-10 12:44:21.175: DEBUG/dalvikvm(429): Debugger has detached; object registry had 1 entries
06-10 12:44:21.215: INFO/ActivityManager(59): Start proc com.SMARTlab.twitter for activity com.SMARTlab.twitter/.Twitter: pid=435 uid=10039 gids={}
06-10 12:44:21.255: INFO/AndroidRuntime(429): NOTE: attach of thread 'Binder Thread #3' failed
06-10 12:44:21.446: DEBUG/dalvikvm(33): GC_EXPLICIT freed 264 objects / 10144 bytes in 203ms
06-10 12:44:21.656: DEBUG/dalvikvm(33): GC_EXPLICIT freed 22 objects / 968 bytes in 163ms
06-10 12:44:21.786: DEBUG/dalvikvm(33): GC_EXPLICIT freed 2 objects / 64 bytes in 115ms
06-10 12:44:22.175: DEBUG/AndroidRuntime(435): Shutting down VM
06-10 12:44:22.175: WARN/dalvikvm(435): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): FATAL EXCEPTION: main
06-10 12:44:22.195: ERROR/AndroidRuntime(435): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.SMARTlab.twitter/com.SMARTlab.twitter.Twitter}: java.lang.ClassNotFoundException: com.SMARTlab.twitter.Twitter in loader dalvik.system.PathClassLoader[/data/app/com.SMARTlab.twitter-1.apk]
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.os.Looper.loop(Looper.java:123)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at java.lang.reflect.Method.invoke(Method.java:521)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at dalvik.system.NativeStart.main(Native Method)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): Caused by: java.lang.ClassNotFoundException: com.SMARTlab.twitter.Twitter in loader dalvik.system.PathClassLoader[/data/app/com.SMARTlab.twitter-1.apk]
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-10 12:44:22.195: ERROR/AndroidRuntime(435): ... 11 more
06-10 12:44:22.205: WARN/ActivityManager(59): Force finishing activity com.SMARTlab.twitter/.Twitter
06-10 12:44:22.716: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{44ff66d0 com.SMARTlab.twitter/.Twitter}
06-10 12:44:25.756: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44eb2308
06-10 12:44:26.025: INFO/Process(435): Sending signal. PID: 435 SIG: 9
06-10 12:44:26.155: INFO/ActivityManager(59): Process com.SMARTlab.twitter (pid 435) has died.
06-10 12:44:28.866: DEBUG/dalvikvm(261): GC_EXPLICIT freed 45 objects / 2120 bytes in 63ms
06-10 12:44:33.570: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{44ff66d0 com.SMARTlab.twitter/.Twitter}
06-10 12:45:37.688: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol
这是AndroidManifest.xml的内容。
<?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>
</manifest>
最佳答案
确保在您的AndroidManifest中将Twitter
注册为活动。
关于java - 编译但崩溃的android应用。与 Intent 有关吗?救命,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6310138/