Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在“活动”中单击URL时出现AndroidRuntimeException_Java_Android_Runtimeexception - Fatal编程技术网

Java 在“活动”中单击URL时出现AndroidRuntimeException

Java 在“活动”中单击URL时出现AndroidRuntimeException,java,android,runtimeexception,Java,Android,Runtimeexception,我有一个带有适配器的活动,扩展了RecyclerView.Adapter。问题是,当用户单击其中一个列表项中的“自动链接”时,会出现以下异常: 在我的UserProfileActivity中,我像他的那样实例化了我的适配器: UserProfileAdapter adapter = new UserProfileAdapter(getApplicationContext(), posts); 在适配器中,我检索如下上下文: private Context mContext; p

我有一个带有适配器的活动,
扩展了RecyclerView.Adapter
。问题是,当用户单击其中一个列表项中的“自动链接”时,会出现以下异常:

在我的UserProfileActivity中,我像他的那样实例化了我的适配器:

UserProfileAdapter adapter = new UserProfileAdapter(getApplicationContext(), posts);
在适配器中,我检索如下上下文:

    private Context mContext;
    private List<ParseObject> mYeets;
    private UserProfileAdapter adapter;

    public UserProfileAdapter(Context context, List<ParseObject> yeets) {
        super();

        this.mYeets = yeets;
        this.mContext = context;
        this.adapter = this;
    }
私有上下文mContext;
私人名单;
私有用户配置文件适配器;
公共UserProfileAdapter(上下文,列表yeets){
超级();
this.mYeets=yeets;
this.mContext=上下文;
this.adapter=this;
}


如何确保自动链接文本不会产生此错误?由于没有与链接/意图关联的代码,我该怎么办?

android.util.AndroidRuntimeException
被抛出,因为在您的应用程序中,正在使用应用程序上下文启动一个活动,而没有标记
标记活动新任务
。Android运行时不允许此类操作,因为没有堆栈可添加此新活动,并且标志_Activity_new_TASK标志对于在应用程序中创建新堆栈很重要

要解决此问题,您可以将活动上下文传递给适配器,而不是应用程序上下文(即:使用
this

e、 g.:
UserProfileAdapter=newuserprofileadapter(这个,posts)


良好实践:始终使用活动上下文处理UI元素。

您截屏的消息中有什么不清楚的地方?启动链接没有实际意图的事实。它是“自动链接”文本,位于回收器列表项之一。所以我不能只是去给意图加上一个标志。