【问题标题】:'Source Not Found' error - attempting to implement simple Activity-Fragment Android application“未找到源”错误 - 尝试实现简单的 Activity-Fragment Android 应用程序
【发布时间】:2011-09-10 14:16:26
【问题描述】:

我正在尝试向我的主要活动添加一个片段,这是 main.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"
    >

    <fragment android:name="wj.tweetTab.Titles"
        android:layout_width="300dp"
        android:layout_height="match_parent" />

</LinearLayout>

wj.tweetTab.Titles 类是 Fragment 类的扩展,它仅覆盖 onCreateView 以扩充其 xml 布局资源:

package wj.tweetTab;

import android.app.Fragment;

public class Titles extends Fragment {
    @Override
public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
    return inflater.inflate(wj.tweetTab.R.layout.titles, container);
}
}

这是标题片段的titles.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"
    >

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="16sp"
        android:text="TEXTTEXTTEXT!!!">
    </TextView>

</LinearLayout>

当我尝试在我的物理 android 选项卡上运行应用程序时,我收到 Source not found 错误。如果我从应用程序运行的main.xml 文件中删除片段 xml。

任何想法为什么会发生这种情况?

【问题讨论】:

    标签: java android


    【解决方案1】:

    环顾四周 - 似乎只要错误来自 Android 二进制文件,就会显示此“找不到源”错误。

    通过查看 eclipse 中的“变量”窗口并检查那里的异常,我设法了解了确切的问题。

    它告诉我片段需要一个 id - 这就是抛出异常的原因。对于 IDE 来说,向您展示异常并不是最有用的方式...浪费了 2 个小时!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 2015-11-03
      • 2014-10-25
      • 2015-01-02
      • 2013-08-26
      • 1970-01-01
      相关资源
      最近更新 更多