Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用com.devsmart.android.ui.HorizontalListView库时,获取膨胀类异常的错误_Android - Fatal编程技术网

使用com.devsmart.android.ui.HorizontalListView库时,获取膨胀类异常的错误

使用com.devsmart.android.ui.HorizontalListView库时,获取膨胀类异常的错误,android,Android,当我在我的项目中使用github的devsmartlibrary时,我的应用程序将崩溃,我无法发现这个错误。我是android新手,请帮助我 这是我的主要活动 package com.example.horizontal; import com.devsmart.android.ui.HorizontalListView; import android.app.Activity; import android.os.Bundle; import android.view.Menu; impo

当我在我的项目中使用github的devsmartlibrary时,我的应用程序将崩溃,我无法发现这个错误。我是android新手,请帮助我 这是我的主要活动

package com.example.horizontal;

import com.devsmart.android.ui.HorizontalListView;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ListView;

public class MainActivity extends Activity {
    String[] itemName = { "OverView", "History", "Budget", "Distribution",
            "Statistics" };
    Integer[] imageId = { R.drawable.image1, R.drawable.image2,
            R.drawable.image3, R.drawable.ic_launcher, R.drawable.image5 };
    ListView lvList;
    GridView gvList;
    CustomerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.horizontal);
        adapter = new CustomerAdapter(this, itemName, imageId);

        // gvList = (GridView) findViewById(R.id.gvList);
        // gvList.setAdapter(adapter);
        HorizontalListView hlv = (HorizontalListView) findViewById(R.id.listview);
        //lvList = (ListView) findViewById(R.id.lvList);
        hlv.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
这是我的horizontal.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <com.devsmart.android.ui.HorizontialListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ddd" />

</LinearLayout>
分析:
  • com.devsmart.android.ui.horizontallistview
    是 您在xml中使用的库项目
  • 如果未正确引用,则会导致二进制Xml错误
你的日志上写着: 意思是:项目中未正确引用库项目

解决方案:
右键单击您的项目
->
Android
->
在右下角
->
单击添加并指向水平库的库项目,以便在您的项目中正确引用它


编辑 horizontal.xml

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"   
     xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#fff"
        android:orientation="vertical"
        tools:context=".MainActivity" >

        <com.devsmart.android.ui.HorizontialListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ddd" />

    </LinearLayout>

您遇到充气错误,这意味着android无法找到您的HorizontalListView类,以下是摆脱此错误的检查列表:

  • 正如@Devrath所说,您必须将库项目添加到项目中,请选中
  • 如果仍然出现此错误,请右键单击project->Properties->select java builder path->select Order and Export->确保必须选中“Android私有库”
  • 如果问题仍未解决,请检查并确保在布局文件中提供了正确的类引用。对于自定义视图,您需要通过包含包名
    .HorizontalListView
    来提供类的完整路径
    我也有同样的问题,我花了很多令人恼火的时间来解决它。我能想到的唯一解决方案是更改devsmart包名,然后将其重新添加到我的项目中,然后将其添加到库中。我相信这是因为我更改了我的项目包名称,所以在使用此库时不要更改您的包名称

    确定首先需要向项目库文件夹“devsmartlibs”添加一个“s” 注意:只有当它不允许您添加项目时,您才需要这样做,因为它已作为项目添加

    然后将其作为项目导入:文件->导入->现有android代码到工作区。然后在“浏览”中选择项目位置并选择“完成”

    然后右键单击您的项目->属性->Android->添加(右下)->现在添加您添加到项目中的新库(devsmartlibs)

    如果这会导致问题,请确保devsmartlibs与您的项目具有相同的“android-support-v4.jar”,因为这会导致问题


    我希望这对我有用。

    我也有同样的问题,然后我下载了它的jar文件,并将其添加到我的项目中。。 您最好使用Recycler视图进行水平滚动,这比水平listView好得多,并且是最新的方法之一。
    其次,如果您仍想使用HSV,请下载此库并将其添加到您的“库”文件夹中,然后右键单击并单击“添加为库并使用HSV”

    我以前使用过此库。。。它起作用了。。。。。。尝试我的编辑和检查一次!我也这么做了,但面临着同样的问题告诉我:当你右键点击你的项目时…->安卓->。。。。。你能看到红色或蓝色的参考项目吗。。。如果红色的话,那就不合适了。。。好啊那么我不确定。。。。你可以再试试。。。。。。。。。。将
    horizontallistview.java
    复制到项目中的某个包中,并在xml中指定该名称,例如:
    com.yourpackage.horizontallistview
    。。。。当然,删除对库项目的引用。。。。希望能成功!解释你的答案。
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.horizontal/com.example.horizontal.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.devsmart.android.ui.HorizontialListView
    03-24 15:19:36.692: E/AndroidRuntime(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
    
     <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:custom="http://schemas.android.com/apk/res-auto"   
         xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#fff"
            android:orientation="vertical"
            tools:context=".MainActivity" >
    
            <com.devsmart.android.ui.HorizontialListView
                android:id="@+id/listview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#ddd" />
    
        </LinearLayout>