gpt4 book ai didi

android - 错误 : Inflating class fragment

转载 作者:行者123 更新时间:2023-11-29 17:30:41 25 4
gpt4 key购买 nike

我是 Android 应用程序开发的新手,目前致力于以编程方式向 Activity 添加 fragment 。

我收到这个错误:

10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: FATAL EXCEPTION: main
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: Process: com.ranapps.listing_agent_trail1, PID: 24020
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ranapps.listing_agent_trail1/com.ranapps.listing_agent_trail1.MainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class fragment
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.access$1100(ActivityThread.java:141)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5336)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:873)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class fragment
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:775)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:512)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:409)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:358)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:1968)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at com.ranapps.listing_agent_trail1.MainActivity.onCreate(MainActivity.java:16)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5302)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313) 
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.access$1100(ActivityThread.java:141) 
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238) 
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136) 
10-15 18:26:32.165 24020-24020/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5336) 

我的 MainActivity.java :

package com.ranapps.listing_agent_trail1;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.FragmentActivity;


public class MainActivity extends FragmentActivity {

private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if(findViewById(R.id.footer) != null){

if(savedInstanceState != null)
return;
}

Footer bottom1 = new Footer();

bottom1.setArguments(getIntent().getExtras());

getSupportFragmentManager().beginTransaction()
.add(R.id.footer, bottom1).commit();

}

}

我的 Footer.java:

public class Footer extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//return super.onCreateView(inflater, container, savedInstanceState);

return inflater.inflate(R.layout.footer_bar, container, false);
}
}

main_activity.xml

 <fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/footer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>

我正在学习 http://developer.android.com/training/basics/fragments/creating.html 上的教程

我搜索了所有类似的问题,但没有一个能解决问题。谢谢。

最佳答案

您还没有指定属性 android:name在你的布局中为 <fragment标签。它必须包含 fragment 的完整路径。例如

 <fragment android:name="com.example.fragments.Footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/footer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>

关于android - 错误 : Inflating class fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33149705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com