03
Фев
2016

Ошибка перехода в фрагменте

Ошибка при нажатии на кнопку(лайтлаут) выдает ошибку

Код фрагмента:

public class sovety_Fragment extends Fragment {

    private static FragmentManager mManager;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_sovety, null);


        mManager = getActivity().getSupportFragmentManager();


        return v;

    }

    public void kat0(View view) {
        Fragment fragment = null;


        mManager.findFragmentById(R.id.fragmentContainer);
        if (fragment == null) {
            fragment = new sovety_Fragment2();
            mManager.beginTransaction()
                    .add(R.id.fragmentContainer, fragment)
                    .addToBackStack(null)
                    .commit();
        }

    }

}

Код лайтлаута:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    tools:showIn="@layout/activity_main">





    <ScrollView
        android:id="@+id/mScroll"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

    <LinearLayout
        android:id="@+id/lin2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="kat0"
        android:orientation="horizontal"
        android:paddingLeft="5.0dip"
        android:paddingRight="5.0dip">

        <ImageView
            android:id="@+id/mImg1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/y11k" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="right"
            android:orientation="vertical"
            android:padding="5.0dip"
            android:layout_marginBottom="@dimen/d1"
            android:background="@drawable/color_gradient_gray"
            android:paddingRight="5.0dip"
            android:paddingTop="5.0dip"
            android:focusableInTouchMode="true">

            <TextView
                android:id="@+id/text_m1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/y_1"
                android:paddingRight="@dimen/d3"
                android:paddingTop="@dimen/d4"
                android:textColor="#ffffffff"
                android:textSize="@dimen/text" />


        </LinearLayout>

    </LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

Код ошибки:

02-03 13:07:42.052 31358-31358/com.whitestar.topcar E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      java.lang.IllegalStateException: Could not find a method kat0(View) in the activity class com.whitestar.topcar.MainActivity for onClick handler on view class android.widget.LinearLayout with id 'lin2'
                                                                          at android.view.View$1.onClick(View.java:3578)
                                                                          at android.view.View.performClick(View.java:4084)
                                                                          at android.view.View$PerformClick.run(View.java:16966)
                                                                          at android.os.Handler.handleCallback(Handler.java:615)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                          at android.os.Looper.loop(Looper.java:137)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:511)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                          at dalvik.system.NativeStart.main(Native Method)
                                                                       Caused by: java.lang.NoSuchMethodException: kat0 [class android.view.View]
                                                                          at java.lang.Class.getConstructorOrMethod(Class.java:460)
                                                                          at java.lang.Class.getMethod(Class.java:915)
                                                                          at android.view.View$1.onClick(View.java:3571)
                                                                          at android.view.View.performClick(View.java:4084) 
                                                                          at android.view.View$PerformClick.run(View.java:16966) 
                                                                          at android.os.Handler.handleCallback(Handler.java:615) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:92) 
                                                                          at android.os.Looper.loop(Looper.java:137) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                                          at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                                          at dalvik.system.NativeStart.main(Native Method) 

Источник: https://ru.stackoverflow.com/questions/488738/%D0%9E%D1%88%D0%B8%D0%B1%D0%BA%D0%B0-%D0%BF%D0%B5%D1%80%D0%B5%D1%85%D0%BE%D0%B4%D0%B0-%D0%B2-%D1%84%D1%80%D0%B0%D0%B3%D0%BC%D0%B5%D0%BD%D1%82%D0%B5

Share

Тебе может это понравится...