金星揽月 2020-05-17 21:49 采纳率: 100%
浏览 960
已采纳

android:从Activity跳转到另一个Activity的Fragment的时候程序报错。

以下是报错信息:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.whut.imageencryptionapp, PID: 31941

java.lang.RuntimeException: 
    **Unable to instantiate activity ComponentInfo****{com.whut.imageencryptionapp/com.whut.imageencryptionapp.ui.ImageHandleActivity}: **java.lang.ClassCastExceptio**n: com.whut.imageencryptionapp.ui.ImageHandleActivity **cannot be cast to android.app.Activity       **

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3678)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:213)
    at android.app.ActivityThread.main(ActivityThread.java:8147)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
 Caused by: java.lang.ClassCastException: com.whut.imageencryptionapp.ui.ImageHandleActivity cannot be cast to android.app.Activity
    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
    at android.support.v4.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:43)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1257)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3663)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3939) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2373) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:213) 
    at android.app.ActivityThread.main(ActivityThread.java:8147) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 

DeImagePickActivity相关代码如下:

            case R.id.iv_image_show_activity_back:
                /*
                Intent intent = new Intent(this, ImageHandleActivity.class);
                startActivity(intent);

                FragmentManager fragmentManager;
                Fragment fragment = new ImageHandleActivity();
                fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.rl_fragment1, fragment).commit();

                fragmentTransaction = fragmentManager.beginTransaction();
                ImageHandleActivity imageHandleActivity = new ImageHandleActivity();
                fragmentTransaction.replace(R.id.ll_de, imageHandleActivity).commit();

                 */

                ImageHandleActivity imageHandleActivity = new ImageHandleActivity();
                FragmentManager fragmentManager;
                fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.rl_fragment1,imageHandleActivity).commit();

                Intent intent = new Intent(this,ImageHandleActivity.class);
                startActivity(intent);

注释中都是我尝试过的方法,但是还是会出现异常。
我要从DeImagePickActivity跳转到ImageHandleActivity,其中ImageHandleActivity继承了Fragment,他的Activity是MainActivity。
感谢解答!

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥50 有没有大佬看一下关于思科的这道题怎么做
      • ¥30 求十字路口交通灯S7-200plc,今天早上八点前。
      • ¥20 如何用智能手表oppowatch3实现个人热点功能
      • ¥15 运营商打开wanpush会有怎么样的危害
      • ¥15 Java编程题,定义一个时钟
      • ¥15 Python面向对象编程——生成多项式的一阶导数
      • ¥15 在编写C++程序遇到了问题
      • ¥15 java程序查找字符串中所有的回文并输出
      • ¥15 怎么让只支持对.exe 和.dll文件进行加壳的加壳器,同时让它也支持php文件加壳呢
      • ¥15 这两个数学公式什么意思?