android – 从片段到活动的意图

我试图使用按钮去另一个页面,但它总是失败.

这是我的头等舱与其XML

public class FindPeopleFragment extends Fragment {
    public FindPeopleFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home,container,false);
        return rootView;
    }

    public void goToAttract(View v)
    {
        Intent intent = new Intent(getActivity().getApplication(),MainActivityList.class);
        startActivity(intent);
    }
}

这是我的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_marginBottom="48dp"
    android:onClick="goToAttract"
    android:text="Button" /></RelativeLayout>

这是我的堆栈跟踪.这是当我使用onclicklistener的结果

12-30 16:54:28.006: E/AndroidRuntime(992): FATAL EXCEPTION: main
12-30 16:54:28.006: E/AndroidRuntime(992): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.slidingmenu/info.androidhive.slidingmenu.MainActivityList}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.os.Looper.loop(Looper.java:137)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-30 16:54:28.006: E/AndroidRuntime(992):  at java.lang.reflect.Method.invokeNative(Native Method)
12-30 16:54:28.006: E/AndroidRuntime(992):  at java.lang.reflect.Method.invoke(Method.java:511)
12-30 16:54:28.006: E/AndroidRuntime(992):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-30 16:54:28.006: E/AndroidRuntime(992):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-30 16:54:28.006: E/AndroidRuntime(992):  at dalvik.system.NativeStart.main(Native Method)
12-30 16:54:28.006: E/AndroidRuntime(992): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-30 16:54:28.006: E/AndroidRuntime(992):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
12-30 16:54:28.006: E/AndroidRuntime(992):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:

解决方法

用这个
public void goToAttract(View v)
{
    Intent intent = new Intent(getActivity(),MainActivityList.class);
    startActivity(intent);
}

确保你已经在你的清单中注册了MainActivityList

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...