我正在尝试使用来自github
的 Gauge View 库
提供的示例应用程序完美!
但是当我尝试将库包含到项目中时(属性>构建路径>项目>(添加库项目)),将视图放在我的布局中并尝试在它抛出的代码中获取对视图的引用ClassNotFoundException
以下是我通过 logcat 得到的错误:
E/AndroidRuntime( 542): FATAL EXCEPTION: main
E/AndroidRuntime( 542): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.guagetest/com.example.guagetest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class org.codeandmagic.android.gauge.GaugeView
E/AndroidRuntime( 542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
E/AndroidRuntime( 542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
E/AndroidRuntime( 542): at android.app.ActivityThread.access$600(ActivityThread.java:122)
E/AndroidRuntime( 542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
E/AndroidRuntime( 542): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 542): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 542): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime( 542): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 542): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 542): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 542): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class org.codeandmagic.android.gauge.GaugeView
E/AndroidRuntime( 542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
E/AndroidRuntime( 542): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
E/AndroidRuntime( 542): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 542): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 542): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 542): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime( 542): at android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime( 542): at com.example.guagetest.MainActivity.onCreate(MainActivity.java:16)
E/AndroidRuntime( 542): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
E/AndroidRuntime( 542): ... 11 more
E/AndroidRuntime( 542): Caused by: java.lang.ClassNotFoundException: org.codeandmagic.android.gauge.GaugeView
E/AndroidRuntime( 542): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime( 542): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 542): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 542): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
E/AndroidRuntime( 542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
E/AndroidRuntime( 542): ... 21 more
W/ActivityManager( 77): Force finishing activity com.example.guagetest/.MainActivity
我不知道为什么它无法找到课程。有人请帮忙。在示例应用程序中我需要做些什么才能让它工作吗?
以下是我的布局:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<org.codeandmagic.android.gauge.GaugeView
android:id="@+id/gauge_view1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
这是我的活动:
package com.example.guagetest;
import org.codeandmagic.android.gauge.GaugeView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private GaugeView gauge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gauge = (GaugeView) findViewById(R.id.gauge_view1);
gauge.setTargetValue(10);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}