android– 碎片无法充气

android– 碎片无法充气,第1张

概述我对此感到有些不满,所以请耐心等待.我正在努力教自己,我目前正在研究WROXAnd​​roid4应用程序开发初学者一书.我目前正处于“碎片之间的通信”部分,我觉得我已经得到了它,但是当我运行从本书中取出的代码时,我在logcat中“无法充气”.这是.java文件后跟的XML,然后是错误.我无法

我对此感到有些不满,所以请耐心等待.我正在努力教自己,我目前正在研究WROX And​​roID 4应用程序开发初学者一书.我目前正处于“碎片之间的通信”部分,我觉得我已经得到了它,但是当我运行从本书中取出的代码时,我在logcat中“无法充气”.这是.java文件后跟的XML,然后是错误.我无法弄清楚是什么杀了这个:

main.xml中:

<linearLayout     xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="horizontal"    >    <fragment        androID:name="com.example.Fragments.Fragment1"        androID:ID="@+ID/fragment1"        androID:layout_weight="1"        androID:layout_wIDth="0px"        androID:layout_height="match_parent"        />    <fragment        androID:name="com.example.Fragments.Fragment2"        androID:ID="@+ID/fragment2"        androID:layout_weight="1"        androID:layout_wIDth="0px"        androID:layout_height="match_parent"        /></linearLayout>

fragment1.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:background="#00FF00"    >    <TextVIEw         androID:ID="@+ID/lblFragment1"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:text="This is fragment #1"        androID:textcolor="#000000"        androID:textSize="25sp"        /></linearLayout>

fragment2.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:background="#FFFE00"    >    <TextVIEw         androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:text="This is fragment #2"        androID:textcolor="#000000"        androID:textSize="25sp"        />    <button        androID:ID="@+ID/btnGetText"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="Get text in Fragment #1"        androID:textcolor="#000000"        androID:onClick="onClick"        /></linearLayout>

FragmentsActivity.java:

package com.example.fragments;import androID.app.Activity;import androID.os.Bundle;public class FragmentsActivity extends Activity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);    }}

Fragment1.java:

package com.example.fragments;import androID.app.Fragment;import androID.os.Bundle;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;public class Fragment1 extends Fragment {    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) {        // ---Inflate the layout for this fragment---        return inflater.inflate(R.layout.fragment1, container, false);    }}

Fragment2.java:

package com.example.fragments;import androID.app.Fragment;import androID.os.Bundle;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.button;import androID.Widget.TextVIEw;import androID.Widget.Toast;public class Fragment2 extends Fragment {    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,             VIEwGroup container, Bundle savedInstanceState) {        //---Inflate the layout for this fragment---        return inflater.inflate(                R.layout.fragment2, container, false);    }    @OverrIDe    public voID onStart() {        super.onStart();        //---button VIEw---        button btnGetText = (button)                getActivity().findVIEwByID(R.ID.btnGetText);        btnGetText.setonClick@R_301_6818@ener(new VIEw.OnClick@R_301_6818@ener() {            public voID onClick(VIEw v) {                TextVIEw lbl = (TextVIEw)                        getActivity().findVIEwByID(R.ID.lblFragment1);                Toast.makeText(getActivity(), lbl.getText(),                         Toast.LENGTH_SHORT).show();            }        });    }}

logcat的:

04-20 15:09:55.759: E/ActivityThread(9523): Failed to inflate04-20 15:09:55.759: E/ActivityThread(9523): androID.vIEw.InflateException: Binary XML file line #7: Error inflating class fragment04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:704)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:746)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:489)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:396)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:352)04-20 15:09:55.759: E/ActivityThread(9523):     at com.androID.internal.policy.impl.PhoneWindow.setContentVIEw(PhoneWindow.java:282)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Activity.setContentVIEw(Activity.java:1881)04-20 15:09:55.759: E/ActivityThread(9523):     at com.example.fragments.FragmentsActivity.onCreate(FragmentsActivity.java:15)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Activity.performCreate(Activity.java:5104)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2260)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.ActivityThread.access0(ActivityThread.java:150)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.os.Handler.dispatchMessage(Handler.java:99)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.os.Looper.loop(Looper.java:137)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.ActivityThread.main(ActivityThread.java:5195)04-20 15:09:55.759: E/ActivityThread(9523):     at java.lang.reflect.Method.invokeNative(Native Method)04-20 15:09:55.759: E/ActivityThread(9523):     at java.lang.reflect.Method.invoke(Method.java:511)04-20 15:09:55.759: E/ActivityThread(9523):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)04-20 15:09:55.759: E/ActivityThread(9523):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:562)04-20 15:09:55.759: E/ActivityThread(9523):     at dalvik.system.NativeStart.main(Native Method)04-20 15:09:55.759: E/ActivityThread(9523): Caused by: androID.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.Fragments.Fragment1: make sure class name exists, is public, and has an empty constructor that is public04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Fragment.instantiate(Fragment.java:592)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Fragment.instantiate(Fragment.java:560)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Activity.onCreateVIEw(Activity.java:4709)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:680)04-20 15:09:55.759: E/ActivityThread(9523):     ... 21 more04-20 15:09:55.759: E/ActivityThread(9523): Caused by: java.lang.classNotFoundException: DIDn't find class "com.example.Fragments.Fragment1" on path: /data/app/com.example.fragments-2.apk04-20 15:09:55.759: E/ActivityThread(9523):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)04-20 15:09:55.759: E/ActivityThread(9523):     at java.lang.classLoader.loadClass(ClassLoader.java:501)04-20 15:09:55.759: E/ActivityThread(9523):     at java.lang.classLoader.loadClass(ClassLoader.java:461)04-20 15:09:55.759: E/ActivityThread(9523):     at androID.app.Fragment.instantiate(Fragment.java:582)04-20 15:09:55.759: E/ActivityThread(9523):     ... 24 more

解决方法:

布局定义错误androID:name =“com.example.Fragments.Fragment1”.它应该是

androID:name="com.example.fragments.Fragment1"

Fragment2也一样

总结

以上是内存溢出为你收集整理的android – 碎片无法充气全部内容,希望文章能够帮你解决android – 碎片无法充气所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106561.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存