填充TableLayout时出错

时间:2016-08-12 00:25:09

标签: java android xml android-fragments

我试图创建一个简单的导航抽屉应用程序并在尝试添加我的初始片段时遇到错误。错误发生在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 Class:

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;
    }

}

片段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>

为什么会这样?

1 个答案:

答案 0 :(得分:0)

案件很重要。使用TableLayout作为标记。 Capital T,Capital L。