简体   繁体   English

包含GaugeView库后,Android ClassNotFoundException

[英]Android ClassNotFoundException after including GaugeView library

I am trying to use the Gauge View from github 我正在尝试使用来自github的Gauge View
The sample application that is given with the library works perfect ! 该库提供的示例应用程序非常完美!

But when i try to include the library into the project (properties > buildpath > projects > (add library project)), put the view in my layout and try to get a reference to the view in code it throws ClassNotFoundException 但是,当我尝试将库包含到项目中(属性> buildpath>项目>(添加库项目))时,将视图放入我的布局中,并尝试在抛出ClassNotFoundException代码中获取对该视图的引用

The following is the error that i get through logcat: 以下是我通过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

I have no idea why it is not able to find the class. 我不知道为什么它找不到课程。 Somebody please help. 有人请帮忙。 Is there anything special that is done in the sample application that i need to do to get it to work ? 为了使它正常工作,示例应用程序中有什么特别的事情要做吗?

the following is my layout: 以下是我的布局:

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

This is my activity: 这是我的活动:

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;
    }

}

You didn't post any code, but the fact that your spelling of a particular word is inconsistent even in your post suggests that you need to check how you're spelling things in your code. 您没有发布任何代码,但是即使在您的帖子中,特定单词的拼写仍然不一致,这一事实表明您需要检查代码中的拼写方式。 Look at these two words carefully: 仔细看这两个词:

String correct = "gauge";
String wrongWrongWrong = "guage";
public class MainActivity extends Activity {

    private GaugeView mGaugeView1;
    private GaugeView mGaugeView2;
    private final Random RAND = new Random();

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mGaugeView1 = (GaugeView) findViewById(R.id.gauge_view1);
        mGaugeView2 = (GaugeView) findViewById(R.id.gauge_view2);
        mTimer.start();
    }

    private final CountDownTimer mTimer = new CountDownTimer(30000, 1000) {

        @Override
        public void onTick(final long millisUntilFinished) {
            mGaugeView1.setTargetValue(RAND.nextInt(101));
            mGaugeView2.setTargetValue(RAND.nextInt(101));
        }

        @Override
        public void onFinish() {}
    };
}

Edit 编辑

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:gauge="http://schemas.android.com/apk/res/org.codeandmagic.android.gauge.samples"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:background="@drawable/background"
    android:padding="20dp" >

   <org.codeandmagic.android.gauge.GaugeView
        android:id="@+id/gauge_view1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <org.codeandmagic.android.gauge.GaugeView
        android:id="@+id/gauge_view2"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_marginTop="10dp"
        gauge:showOuterShadow="true"
        gauge:showOuterRim="false"
        gauge:showNeedle="false"
        gauge:showRanges="false"
        gauge:showText="true"
        gauge:textUnit="%" />

</LinearLayout>

Gauge that you are using have bugs and don't run fine on Kitkat and Lollipop. 您使用的仪表存在错误,在Kitkat和Lollipop上无法正常运行。 Also there is no Android Studio and gradle friendly library here. 另外,这里没有Android Studio和gradle友好库。

This here is basically the same library you are using but forked from other developer and updated to work for new versions of android. 这基本上是您正在使用的相同库,但已从其他开发人员分叉,并已更新为可用于新版本的android。 Also you can use with Gradle and include easy in your project without any errors: 您也可以与Gradle一起使用,并轻松地将其包含在项目中,而不会出现任何错误:

http://www.sule.io/?p=25 http://www.sule.io/?p=25

在此处输入图片说明

After you include library in your project add gaugelibrary to xml layout of your activity: 在项目中包含库之后,将gaugelibrary添加到活动的xml布局中:

<io.sule.gaugelibrary.GaugeView
 android:id="@+id/gauge_view"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#ffffff"
 gauge:showOuterShadow="false"
 gauge:showOuterRim="false"
 gauge:showInnerRim="false"
 gauge:needleWidth="0.010"
 gauge:needleHeight="0.40"
 gauge:scaleStartValue="0"
 gauge:scaleEndValue="100"
 />

This will show static gauge without needle. 这将显示不带针的静态压力表。 To instantiate needle with random animation you need to do that in activity class file. 要使用随机动画实例化针,您需要在活动类文件中进行。 See how it's done here: 在这里查看如何完成:

package io.sule.testapplication;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Menu;
import android.view.MenuItem;

import java.util.Random;

import io.sule.gaugelibrary.GaugeView;

public class MainActivity extends Activity {
   private GaugeView mGaugeView;
   private final Random RAND = new Random();

   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

      mGaugeView = (GaugeView) findViewById(R.id.gauge_view);
      mTimer.start();
   }


   private final CountDownTimer mTimer = new CountDownTimer(30000, 1000) {

      @Override
      public void onTick(final long millisUntilFinished) {
         mGaugeView.setTargetValue(RAND.nextInt(101));
      }

      @Override
      public void onFinish() {}
   };
}

This will instantiate needle and make it animate moving to random values. 这将实例化针并使其动画化为随机值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 包含库jar时的ClassNotFoundException - ClassNotFoundException when including a library jar 包含库项目(Eclipse,Andrdoid)时发生ClassNotFoundException - ClassNotFoundException when including Library Project (Eclipse,Andrdoid) 在 Android 生成文件中包含支持库 - ClassnotfoundException - Including support libraries in Android makefile - ClassnotfoundException 包含 Google Cloud Client 库后在 Android Studio 中构建错误 - Building error in Android Studio after including Google Cloud Client library Android库项目上的java.lang.ClassNotFoundException - java.lang.ClassNotFoundException on Android Library Project Android:包含用于Retrofit2的SimpleXML转换器时,ClassNotFoundException - Android: ClassNotFoundException when including SimpleXML converter for Retrofit2 使用Jack Android重新部署后,生成类具有ClassNotFoundException - ClassNotFoundException with generated class after redeploy with jack android Android应用导出到APK后获取ClassNotFoundException - Android app gets ClassNotFoundException after exported to apk 在项目中包括 jar。 并包括 Android 库项目 - Including jar in project. And including Android Library project Java ClassNotFoundException,即使在检查库中的正确类之后 - Java ClassNotFoundException even after checking for correct class in library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM