错误:(28)解析XML时出错:没有找到元素

错误:(28)解析XML时出错:没有找到元素

问题描述:

我有这个错误,我不知道如何解决它。当我尝试添加第三方库XML元素时发生错误,但我无法解决它。错误:(28)解析XML时出错:没有找到元素

有些地方告诉我,这是一个Android Studio问题,它通过重新启动程序解决,我做到了,并没有解决问题。下面是代码:

public class HorizontalNtbActivity extends Activity { 

    @Override 
    protected void onCreate(final Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_horizontal_ntb); 
     initUI(); 
    } 

    private void initUI() { 
     final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb); 
     viewPager.setAdapter(new PagerAdapter() { 
      @Override 
      public int getCount() { 
       return 5; 
      } 

      @Override 
      public boolean isViewFromObject(final View view, final Object object) { 
       return view.equals(object); 
      } 

      @Override 
      public void destroyItem(final View container, final int position, final Object object) { 
       ((ViewPager) container).removeView((View) object); 
      } 

      @Override 
      public Object instantiateItem(final ViewGroup container, final int position) { 
       final View view = LayoutInflater.from(
         getBaseContext()).inflate(R.layout.item_vp, null, false); 

       final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); 
       txtPage.setText(String.format("Page #%d", position)); 

       container.addView(view); 
       return view; 
      } 
     }); 

     final String[] colors = getResources().getStringArray(R.array.default_preview); 

     final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal); 
     final ArrayList<NavigationTabBar.Model> models = new ArrayList<>(); 
     models.add(
       new NavigationTabBar.Model.Builder(
         getResources().getDrawable(R.drawable.ic_first), 
         Color.parseColor(colors[0])) 
         .selectedIcon(getResources().getDrawable(R.drawable.ic_sixth)) 
         .title("Heart") 
         .badgeTitle("NTB") 
         .build() 
     ); 
     ... 
    } 
    .... 
} 

activity_main.xml中:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="#423752" 
    android:orientation="vertical"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/PostList" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <devlight.io.library.ntb.NavigationTabBar 
     android:id="@+id/ntb_horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     app:ntb_badge_gravity="top" 
     app:ntb_badge_position="right" 
     app:ntb_badged="true" 
     app:ntb_scaled="true" 
     app:ntb_tinted="true" 
     app:ntb_title_mode="all" 
     app:ntb_titled="true" 
     app:ntb_swiped="true"/> 
    ... 
</LinearLayout> 
+2

寻求调试帮助的问题('**为​​什么不是这个代码工作?**')必须包含所需的行为,特定的问题或错误以及在问题本身中重现**的最短代码** 。没有**明确问题陈述**的问题对其他读者没有用处。请参阅:[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – Biffen

我假设你的问题的称号意味着你得到错误代码28的错误谷歌搜索为了这个,我发现this page指出错误代码28意味着:

The version information wasn’t present in the XML declaration.

因此,要解决这个错误,只需添加你的第一个标签上面下面一行r布局:

<?xml version="1.0" encoding="utf-8"?> 

希望这有助于!