java - 膨胀 TableLayout 时出错

标签 java android xml android-fragments

我正在尝试创建一个简单的抽屉导航应用程序,但当我尝试添加初始 fragment 时遇到错误。错误如下 java.lang.RuntimeException: Unable to start Activity ComponentInfo{com.tble.brgo/com.tble.brgo.BRGO}: android.view.InflateException: Binary XML file line #3: Binary XML file line #3: Error inflating class Linearlayout

这是我的主类 onCreate:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brgo);
        News initial = new News();
        FragmentTransaction transfer = getSupportFragmentManager().beginTransaction();
        transfer.replace(R.id.fragmentcontainer, initial);
        transfer.commit();
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState(); 
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

fragment Java 类:

public class News extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER


    public News() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment News.
     */
    // TODO: Rename and change types and number of parameters
    public static News newInstance() {
        News fragment = new News();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_news, container, false);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
        if (getArguments() != null) {
        }
        HTMLPull Connection = new HTMLPull();
        ArrayList<InfoArticle> data = new ArrayList<InfoArticle>();
        try {
            data = Connection.XmlPull("http://www.brrsd.org/apps/news/news_rss.jsp?id=0");
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        TableLayout tables = (TableLayout) view.findViewById(R.id.NewsTable);
        for(InfoArticle set: data)
        {
            TableRow temp = new TableRow(getContext());
            TextView title = new TextView(getContext());
            title.setText(set.title);
            temp.addView(title);
            tables.addView(temp);

        }
        return view;
    }

}

fragment XML:

<tablelayout 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:id="@+id/NewsTable"
    tools:context="layout.News">

</tablelayout>

为什么会发生这种情况?

最佳答案

案例很重要。使用 TableLayout 作为标签。大写 T,大写 L。

关于java - 膨胀 TableLayout 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908053/

相关文章:

java - 如何在 Android 本地存储中存储登录详细信息

java - 准备语句: Missing expression on single quote (ORA-00936)

java - 在保持LogicalTypes的同时将Parquet/Avro GenericRecord写入JSON

html - PDF 到结构化格式

java - JTextArea 在父缩小时不换行

java - 在其他 Activity 中调用一个类并更改其变量之一

android - PhoneGap+Cordova 应用程序无法在 AVD(Android 虚拟设备)上运行

android - 如何从 Fragment 或 Activity 调用挂起函数?

java - Tomcat context.xml 的 Netbeans 问题

java - 解析 XML 的算法