2016-08-12 76 views
0

我試圖創建一個簡單的導航抽屜應用程序,並在嘗試添加我的初始片段時遇到錯誤。因爲是錯誤如下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錯誤充氣TableLayout

這裏是我的主類的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); 
    } 

片段的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; 
    } 

} 

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

這是爲什麼發生了什麼?

回答

0

案件事宜。使用TableLayout作爲標籤。 Capital T,Capital L.