次の強制終了エラーが発生します: java.lang.ClassCastException: com.example.httpgetandroidexample.HttpGetAndroidExample cannot be cast to android.app
次のコードを実行しようとすると、理由がわかりません。
package com.example.httpgetandroidexample;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class HttpGetAndroidExample {
public static void main(String[] args) {
Document doc;
try {
// need http protocol
doc = Jsoup.connect("http://www.sheriff.org/apps/arrest/results.cfm?lname=smith&fname=").get();
// get page title
String title = doc.title();
System.out.println("Arrest # : " + title);
// get all links
Elements links = doc.select("a[href]");
for (Element link : links) {
// get the value from href attribute
System.out.println("\nlink : " + link.attr("href"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
ログキャット:
07-18 15:41:43.330: D/ActivityThread(8349): setTargetHeapUtilization:0.25
07-18 15:41:43.330: D/ActivityThread(8349): setTargetHeapIdealFree:8388608
07-18 15:41:43.330: D/ActivityThread(8349): setTargetHeapConcurrentStart:2097152
07-18 15:41:43.350: W/dalvikvm(8349): threadid=1: thread exiting with uncaught exception (group=0x41e1f438)
07-18 15:41:43.350: E/AndroidRuntime(8349): FATAL EXCEPTION: main
07-18 15:41:43.350: E/AndroidRuntime(8349): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.httpgetandroidexample/com.example.httpgetandroidexample.HttpGetAndroidExample}: java.lang.ClassCastException: com.example.httpgetandroidexample.HttpGetAndroidExample cannot be cast to android.app.Activity
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2012)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread.access$700(ActivityThread.java:139)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.os.Looper.loop(Looper.java:137)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread.main(ActivityThread.java:4918)
07-18 15:41:43.350: E/AndroidRuntime(8349): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 15:41:43.350: E/AndroidRuntime(8349): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 15:41:43.350: E/AndroidRuntime(8349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
07-18 15:41:43.350: E/AndroidRuntime(8349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
07-18 15:41:43.350: E/AndroidRuntime(8349): at dalvik.system.NativeStart.main(Native Method)
07-18 15:41:43.350: E/AndroidRuntime(8349): Caused by: java.lang.ClassCastException: com.example.httpgetandroidexample.HttpGetAndroidExample cannot be cast to android.app.Activity
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
07-18 15:41:43.350: E/AndroidRuntime(8349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2003)
07-18 15:41:43.350: E/AndroidRuntime(8349): ... 11 more
07-18 15:42:53.765: D/ActivityThread(8635): setTargetHeapUtilization:0.25
07-18 15:42:53.765: D/ActivityThread(8635): setTargetHeapIdealFree:8388608
07-18 15:42:53.765: D/ActivityThread(8635): setTargetHeapConcurrentStart:2097152
07-18 15:42:53.785: W/dalvikvm(8635): threadid=1: thread exiting with uncaught exception (group=0x41e1f438)
07-18 15:42:53.785: E/AndroidRuntime(8635): FATAL EXCEPTION: main
07-18 15:42:53.785: E/AndroidRuntime(8635): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.httpgetandroidexample/com.example.httpgetandroidexample.HttpGetAndroidExample}: java.lang.ClassCastException: com.example.httpgetandroidexample.HttpGetAndroidExample cannot be cast to android.app.Activity
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2012)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread.access$700(ActivityThread.java:139)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.os.Looper.loop(Looper.java:137)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread.main(ActivityThread.java:4918)
07-18 15:42:53.785: E/AndroidRuntime(8635): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 15:42:53.785: E/AndroidRuntime(8635): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 15:42:53.785: E/AndroidRuntime(8635): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
07-18 15:42:53.785: E/AndroidRuntime(8635): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
07-18 15:42:53.785: E/AndroidRuntime(8635): at dalvik.system.NativeStart.main(Native Method)
07-18 15:42:53.785: E/AndroidRuntime(8635): Caused by: java.lang.ClassCastException: com.example.httpgetandroidexample.HttpGetAndroidExample cannot be cast to android.app.Activity
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
07-18 15:42:53.785: E/AndroidRuntime(8635): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2003)
07-18 15:42:53.785: E/AndroidRuntime(8635): ... 11 more
マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.httpgetandroidexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.httpgetandroidexample.HttpGetAndroidExample"
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>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>