【发布时间】:2016-12-08 05:59:48
【问题描述】:
我正在使用选项卡活动并添加片段和活动。现在我想通过单击片段中的按钮来打开活动,当我单击按钮时应用程序崩溃错误发生应用程序停止不幸,这不起作用。
我正在使用此代码:
public class SmsList extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootview = inflater.inflate(R.layout.fragment_sms_list, container, false);
Button button1 = (Button)rootview.findViewById(R.id.btinboxsms);
Button button2 = (Button)rootview.findViewById(R.id.btsetetime);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent i = new Intent(getActivity(), InboxSms.class);
startActivity(i);
}
});
return rootview;
}
}
java.lang.IllegalStateException:无法在父或祖先上下文中找到方法 setListFooter(View) 为 android:onClick 属性定义在视图类 android.support.v7.widget.AppCompatButton 上,id 为“btinboxsms”
【问题讨论】:
-
分享错误日志,希望你在 xml 中做错了
-
您是否在清单中定义了活动?
-
尝试使用 onclick 监听器移除 view.Onclicklistener : button1.setOnClickListener(new OnClickListener() {}
-
java.lang.IllegalStateException:无法在父或祖先上下文中找到方法 setListFooter(View) 为 android:onClick 属性定义在视图类 android.support.v7.widget.AppCompatButton 与 id 'btinboxsms '