2

Listfragment の拡張クラスを使用しようとしていますが、開くことができません。

2 つのアクティビティがあります。最初はメインで、ActionBarActivity を拡張してアクション バーを古い API に取得します。

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;


    public class MainActivity extends  ActionBarActivity {

    //......

    public void makeAndEvent (View v){

    Intent intent = new Intent(getBaseContext(), Events.class);
            startActivity(intent);
        }
    }

秒はここでの競合です:

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public class Events extends ListFragment {



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_events, container, false);
        return rootView;
    }
}

しかし、アプリが 2 番目のアクティビティであるイベントを起動しようとすると、次のエラーがログに記録されます。

08-02 18:59:38.279: E/AndroidRuntime(12284): FATAL EXCEPTION: main
08-02 18:59:38.279: E/AndroidRuntime(12284): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.app.myapp/com.app.myapp.Events}: java.lang.ClassCastException: com.app.myapp.Events cannot be cast to android.app.Activity
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1998)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.os.Looper.loop(Looper.java:137)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread.main(ActivityThread.java:4929)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at java.lang.reflect.Method.invokeNative(Native Method)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at java.lang.reflect.Method.invoke(Method.java:511)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at dalvik.system.NativeStart.main(Native Method)
08-02 18:59:38.279: E/AndroidRuntime(12284): Caused by: java.lang.ClassCastException: com.app.myapp.Events cannot be cast to android.app.Activity
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.Instrumentation.newActivity(Instrumentation.java:1056)
08-02 18:59:38.279: E/AndroidRuntime(12284):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1989)

誰かが私を助けることができますか?

4

1 に答える 1