gpt4 book ai didi

android - 超链接获取 AndroidRuntimeException

转载 作者:行者123 更新时间:2023-11-30 02:11:57 25 4
gpt4 key购买 nike

我在这个应用程序中使用 ViewPagerSherlockFragments 并尝试在 TextView 中设置超链接。当我点击超链接时,应用程序崩溃了。此方法之前在其他应用程序中有效,但现在我遇到了 AndroidRuntimeException。

public class FragmentNewsPage extends SherlockFragment {
/*
*
**/
public void newsShow(String news) {

mShareIntent.putExtra(Intent.EXTRA_TEXT, news);

swipeRefreshLayout.setRefreshing(false);

mMainText.setMovementMethod(LinkMovementMethod.getInstance());
mMainText.setText(Html.fromHtml(mLink));
mMainText.append("\n\n" + news);

}
}

布局

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_page"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/newsText"
android:textSize="20sp"
android:textStyle="bold"
android:clickable="true"
android:textColor="@android:color/white"
android:layout_gravity="center_horizontal"/>
</ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

<LinearLayout
android:id="@+id/linearLayout_newsPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:orientation="horizontal"/>

</RelativeLayout>

记录错误

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1146)
at android.app.ContextImpl.startActivity(ContextImpl.java:1133)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:328)
at android.text.style.URLSpan.onClick(URLSpan.java:64)
at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
at android.widget.TextView.onTouchEvent(TextView.java:8200)
at android.view.View.dispatchTouchEvent(View.java:7881)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2324)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2029)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2124)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1556)
at android.app.Activity.dispatchTouchEvent(Activity.java:2502)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2072)
at android.view.View.dispatchPointerEvent(View.java:8072)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4392)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4263)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3859)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3828)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3935)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3836)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3859)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3828)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3836)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3809)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6124)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6104)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6058)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6254)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.r

最佳答案

尝试从 Activity 上下文中调用新 Activity ,例如:

getActivity().startActivity(...);

关于android - 超链接获取 AndroidRuntimeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29969765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com