我如何调试这个"由"错误?

时间:2016-02-12 17:58:45

标签: android android-fragments

我是android studio的新手程序员,我需要帮助我如何调试我在片段中获得的错误。它总是会停止我的应用程序。

这是由以下原因引起的错误:

  

引起:java.lang.RuntimeException:   com.example.marlon.testproject.MainActivity@665ba92必须实现   com.example.marlon.testproject.TestFragment.onAttach(TestFragment.java:84)上的OnFragmentInteractionListener

以下是它所指向的代码:

@Override
public void onAttach(Context context)
{
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener)
    {
        mListener = (OnFragmentInteractionListener) context;
    }
    else
    {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}

1 个答案:

答案 0 :(得分:1)

我知道堆栈跟踪看起来真的很可怕,但有时候(就像在这个时候一样)它们几乎用简单的英语写成。

com.example.marlon.testproject。 MainActivity @ 665ba92 必须实现OnFragmentInteractionListener

另外,这就是你自己编写的字符串:

  

抛出新的RuntimeException(context.toString()                   +“必须实现OnFragmentInteractionListener”);