Process: sg.edu.tp.quixmovie, PID: 13707
java.lang.IllegalStateException: Could not find method moviePoster1(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageView with id 'imageView6'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:423)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:380)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-19 08:53:23.900 13707-13707/sg.edu.tp.quixmovie I/Process: Sending signal. PID: 13707 SIG: 9
当前,我正在尝试将我的fragment_home onclick ImageView设置为Movie1.class,但是它不起作用。它一直崩溃,我不知道为什么。.需要帮助谢谢。
AndroidManifest.xml:
Logcat:
Home.Java:
答案 0 :(得分:0)
尝试这种方法...
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
ImageView iv = (ImageView) view.findViewById(R.id.imageView6);
iv.setOnClickListener(this);
return view;
}
答案 1 :(得分:0)
尝试这个
public class Home extends Fragment implements View.OnClickListener {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
ImageView iv = view.findViewById(R.id.iv_click);
iv.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.tv_click) {
Toast.makeText(getContext(), "dssas", Toast.LENGTH_LONG).show();
}
}
}
答案 2 :(得分:0)
我认为问题出在包含contains(g1, g2) uses MBR only (not exact!)
st_contains(g1, g2) uses exact shapes
的{{1}}文件中,您是否将XML
属性设置为ImageView?如果是,则删除该行并使用其他答案中提到的imageView6
如果您想使用android:onClick
,请执行以下操作:
在XML中
setOnClickListener
在HomeActivity中
android:onClick