0

尝试在启动时加载我的片段时出现错误。

我的错误日志在这里:

08-07 00:02:31.918: E/AndroidRuntime(2652): FATAL EXCEPTION: main
08-07 00:02:31.918: E/AndroidRuntime(2652): java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.ioto.atractr_v2/ca.ioto.atractr_v2.Atractr}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.os.Looper.loop(Looper.java:137)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at java.lang.reflect.Method.invokeNative(Native Method)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at java.lang.reflect.Method.invoke(Method.java:511)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at dalvik.system.NativeStart.main(Native Method)
08-07 00:02:31.918: E/AndroidRuntime(2652): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.Activity.setContentView(Activity.java:1881)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at ca.ioto.atractr_v2.Atractr.onCreate(Atractr.java:37)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.Activity.performCreate(Activity.java:5104)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-07 00:02:31.918: E/AndroidRuntime(2652):     ... 11 more
08-07 00:02:31.918: E/AndroidRuntime(2652): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f080002 type #0x12 is not valid
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:2144)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.content.res.Resources.getLayout(Resources.java:853)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at ca.ioto.atractr_v2.ChatFragment.onCreateView(ChatFragment.java:30)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.Fragment.performCreateView(Fragment.java:1695)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:861)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.app.Activity.onCreateView(Activity.java:4717)
08-07 00:02:31.918: E/AndroidRuntime(2652):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
08-07 00:02:31.918: E/AndroidRuntime(2652):     ... 21 more

异常发生在setContentView我的OnCreate方法行:

super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_atractr);
    newFragment = (FindNearestDevicesFragment)getFragmentManager().findFragmentById(R.id.nearest_fragment);
    chatFragment = (ChatFragment)getFragmentManager().findFragmentById(R.id.chat_fragment);
    if (!chordStarted) {
        initializeChord();
    }
    newFragment.setListener(this);

我的活动的 XML 在这里:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Atractr" >

<fragment
    android:id="@+id/fragment1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    class ="ca.ioto.atractr_v2.FindNearestDevicesFragment"
    tools:layout="@layout/findnearestdevices_fragment" />

<fragment
    android:id="@+id/fragment2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/fragment1"
    android:layout_alignTop="@+id/fragment1"
    class="ca.ioto.atractr_v2.ChatFragment"
    tools:layout="@layout/chat_fragment" />

这很令人沮丧,因为我想做的只是在fragment1and之间切换fragment2,现在我什至无法启动我的应用程序。

我觉得我错过了一些非常简单的东西,我现在看不到它。

4

1 回答 1

0

根据您的错误消息,Android 似乎找不到 ca.ioto.atractr_v2.ChatFragment 片段的布局。你确定你指定的布局是正确的(拼写和所有)?另外,是否有适合您的屏幕尺寸的布局?(我不知道如果您尝试膨胀当前屏幕尺寸没有布局的布局,Android 是否会引发错误,所以这可能是个问题。)

最后,尝试重建项目(完全清洁 + 构建)。也许构建系统以某种方式搞砸了。

于 2013-08-07T00:23:07.363 回答