当我在我的项目中使用来自github的devsmartliberary我的应用程序将崩溃我无法找出此错误。我是新来的android plz帮助我 这是我的主要活动
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>
异常即将到来
03-24 15:19:36.692: E/AndroidRuntime(881): FATAL EXCEPTION: main
03-24 15:19:36.692: E/AndroidRuntime(881): 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)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.os.Looper.loop(Looper.java:137)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-24 15:19:36.692: E/AndroidRuntime(881): at java.lang.reflect.Method.invokeNative(Native Method)
03-24 15:19:36.692: E/AndroidRuntime(881): at java.lang.reflect.Method.invoke(Method.java:511)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-24 15:19:36.692: E/AndroidRuntime(881): at dalvik.system.NativeStart.main(Native Method)
03-24 15:19:36.692: E/AndroidRuntime(881): Caused by: 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.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.Activity.setContentView(Activity.java:1835)
03-24 15:19:36.692: E/AndroidRuntime(881): at com.example.horizontal.MainActivity.onCreate(MainActivity.java:26)
03-24 15:19:36.692: E/AndroidRuntime(881): at android.app.Activity.performCreate(Activity.java:4465)
答案 0 :(得分:1)
com.devsmart.android.ui.HorizontialListView
是来自的类路径
您在xml中使用的库项目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)
表示: 您的项目中没有正确引用库项目
Right click on your project
- &gt; Android
- &gt; in the right bottom
- &gt; click add and point to the library project of horizontal library, so that it is refered properly in your project
<强> 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>
答案 1 :(得分:1)
我有同样的问题,然后我下载了它的jar文件,并在我的项目中添加了.. 您最好使用Recycler View进行水平滚动,这比Horizontal listView要好得多,并且是最新的方法之一。 其次,如果您仍想使用HSV,请下载此https://www.dropbox.com/s/ihfmr149z6liabb/devsmartlib.jar?dl=0库并将其添加到您的库文件夹中,然后右键单击并单击添加为库并使用HSV
答案 2 :(得分:0)
你得到了膨胀错误,这意味着android无法找到你的HorizontalListView类,这里是检查列表以摆脱这个错误:
<packagename>.HorizontalListView
来提供课程的完整路径。 答案 3 :(得分:0)
我遇到了同样的问题,我花了很多时间来搞清楚这个问题。我能想到的唯一解决方案是更改devsmart软件包名称,然后将其重新添加到我的项目中,然后将其添加到库中。我相信这开始是因为我改变了我的项目包名称,所以在使用这个库时我不会改变你的包名。
好的,首先你需要添加一个&#39;到项目库文件夹&#39; devsmartlibs&#39; 注意:如果它不允许您添加项目,那么您只需要这样做,因为它已经被添加为项目。
然后将其作为项目导入,以便:文件 - &gt;导入 - &gt;现有的android代码进入工作区。然后在浏览中选择项目位置并选择完成。
然后右键单击您的项目 - &gt;属性 - &gt; Android - &gt;添加(右下) - &gt;现在添加您已添加到项目中的新库(devsmartlibs)。
如果这导致问题,请确保devsmartlibs具有相同的&#39; android-support-v4.jar&#39;作为你的项目,因为这可能会导致问题。
这对我有用,我希望它有所帮助。