当我单击需要打开页面的文本视图时,我在数组中有一些 url,但我收到错误我的代码是
LinearLayout l = new LinearLayout(this);
l.setOrientation(LinearLayout.VERTICAL);
String[] textArray={"www.google.co.in","www.gmail.com","www.facebook.com"};
int length=textArray.length;
LinearLayout layout = new LinearLayout(this);
setContentView(layout);
layout.setOrientation(LinearLayout.VERTICAL);
for(int i=0;i<length;i++)
{
TextView tv=new TextView(getApplicationContext());
tv.setText(textArray[i]);
layout.addView(tv);
Linkify.addLinks(tv, Linkify.WEB_URLS);
tv.setMovementMethod(LinkMovementMethod.getInstance())
LogCat 输出
12-20 16:08:38.623: E/InputEventReceiver(2170): Exception dispatching input event.
12-20 16:08:38.623: E/MessageQueue-JNI(2170): Exception in MessageQueue callback: handleReceiveCallback
12-20 16:08:38.804: E/MessageQueue-JNI(2170): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.text.style.URLSpan.onClick(URLSpan.java:62)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.widget.TextView.onTouchEvent(TextView.java:7397)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.View.dispatchTouchEvent(View.java:7239)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.View.dispatchPointerEvent(View.java:7419)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.MessageQueue.nativePollOnce(Native Method)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.MessageQueue.next(MessageQueue.java:125)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.Looper.loop(Looper.java:124)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at dalvik.system.NativeStart.main(Native Method)
12-20 16:08:38.804: D/AndroidRuntime(2170): Shutting down VM
12-20 16:08:38.813: W/dalvikvm(2170): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-20 16:08:38.913: E/AndroidRuntime(2170): FATAL EXCEPTION: main
12-20 16:08:38.913: E/AndroidRuntime(2170): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.text.style.URLSpan.onClick(URLSpan.java:62)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.widget.TextView.onTouchEvent(TextView.java:7397)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.View.dispatchTouchEvent(View.java:7239)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.View.dispatchPointerEvent(View.java:7419)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.MessageQueue.nativePollOnce(Native Method)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.MessageQueue.next(MessageQueue.java:125)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.Looper.loop(Looper.java:124)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-20 16:08:38.913: E/AndroidRuntime(2170): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 16:08:38.913: E/AndroidRuntime(2170): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-20 16:08:38.913: E/AndroidRuntime(2170): at dalvik.system.NativeStart.main(Native Method)