3

我有一个主要活动。其中我有一些操作按钮。我想当我按下一个按钮时,一个新的活动将开始,其中包含两个片段。但是当我点击按钮时,它给我错误前关闭。我正在通过意图从活动导航到另一个活动。这是我的意图代码

if(v.getId()==R.id.Search)
{
    Intent i=new Intent(MainActivity.this,Search.class);
    startActivity(i);
}

这是我的日志文件

12-04 09:32:43.501: E/Trace(768): error opening trace file: No such file or directory (2)
12-04 09:32:46.812: E/AndroidRuntime(768): FATAL EXCEPTION: main
12-04 09:32:46.812: E/AndroidRuntime(768): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.student_managment/com.example.student_managment.Search}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.os.Looper.loop(Looper.java:137)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread.main(ActivityThread.java:4745)
12-04 09:32:46.812: E/AndroidRuntime(768):  at java.lang.reflect.Method.invokeNative(Native Method)
12-04 09:32:46.812: E/AndroidRuntime(768):  at java.lang.reflect.Method.invoke(Method.java:511)
12-04 09:32:46.812: E/AndroidRuntime(768):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-04 09:32:46.812: E/AndroidRuntime(768):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-04 09:32:46.812: E/AndroidRuntime(768):  at dalvik.system.NativeStart.main(Native Method)
12-04 09:32:46.812: E/AndroidRuntime(768): Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-04 09:32:46.812: E/AndroidRuntime(768):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.Activity.setContentView(Activity.java:1867)
12-04 09:32:46.812: E/AndroidRuntime(768):  at com.example.student_managment.Search.onCreate(Search.java:13)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.Activity.performCreate(Activity.java:5008)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-04 09:32:46.812: E/AndroidRuntime(768):  ... 11 more
12-04 09:32:46.812: E/AndroidRuntime(768): Caused by: java.lang.ClassCastException: com.example.student_managment.Lower_frag cannot be cast to android.support.v4.app.Fragment
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.support.v4.app.Fragment.instantiate(Fragment.java:388)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.support.v4.app.Fragment.instantiate(Fragment.java:363)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264)
12-04 09:32:46.812: E/AndroidRuntime(768):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-04 09:32:46.812: E/AndroidRuntime(768):  ... 21 more
4

1 回答 1

0

该错误Caused by: java.lang.ClassCastException: com.example.student_managment.Lower_frag cannot be cast to android.support.v4.app.Fragment意味着您可能声明了一个不是片段的片段(在您的 Search.class 中膨胀的 xml 布局中)。检查 Search.class 中膨胀的布局

于 2013-03-06T00:22:39.980 回答