Fragment中点击事件跳转活动报错

本来想实现点击“售后服务”这一块的Linearlayout跳转到Guarantee这个活动当中这一功能

public class ThirdFragment extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.third_fragment, container, false);
LinearLayout guaranteell = (LinearLayout) view.findViewById(R.id.serviceGuaranteeId);
guaranteell.setOnClickListener(this);
return view;
}
@Override
public void onClick(View view){
MainActivity mainActivity = new MainActivity();
Intent intent = new Intent(mainActivity, Guarantee.class);
startActivity(intent);
//Toast.makeText(mainActivity, "you clicked this", Toast.LENGTH_SHORT).show();
}
}

https://img2.mukewang.com/5b6e96010001de9503400591.jpg

  • 但是报错java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference


富国沪深
浏览 705回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java