代码之家  ›  专栏  ›  技术社区  ›  Abhishek kumar

Android HighCharts库返回错误:未能解析:com。highsoft。高图:6.0.2:

  •  1
  • Abhishek kumar  · 技术社区  · 7 年前

    几天前我看到 HighCharts库 适用于Android for graph。

    https://github.com/highcharts/highcharts-android

    我阅读了文档并开始将其添加到我的项目中,但当我尝试将gradle添加到我的项目中时,我遇到了错误:

    错误:无法解析:com。highsoft。高图:6.0.2:
    打开文件

    enter image description here

    正如他们在文档中提到的,有两种方式:

    A) 您可以从这里下载aar:Highcharts并手动添加。将aar放在项目结构的libs文件夹中。

    B) 您可以从JCenter将库添加到渐变依赖项中。

    当我添加时。aar文件到libs文件夹没有问题,但我添加了以下代码:

    HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);
    

    我的项目无法找到类 HIGChartView 。我无法确定这是我的副刊还是HighCharts Library的期刊。

    我还下载了Github的poject,对他们的项目没有任何问题,也将Gradle与他们的项目进行了比较,但我无法找出问题所在。

    我的 建筑gradle(模块:应用程序):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.kabloom.highcharts2"
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
    
        implementation 'com.highsoft.highcharts:6.0.2' // HighCharts here added
    
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
    
    1 回复  |  直到 4 年前
        1
  •  1
  •   Abhishek kumar    7 年前

    在github上创建问题后,他们回复并解决了我的问题。。。

    他们的文档有问题 :

    enter image description here

    不正确的类别:

    HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);
    

    正确的类别:

    HIChartView chartView = (HIChartView) findViewById(R.id.hc);
    

    请注意,库需要Gson才能工作,因此请将其添加到依赖项中,如下所示:

    compile 'com.google.code.gson:gson:2.8.0'
    

    他们还回答说:

    不幸的是,Highcharts Android还不能从jcenter获得支持,所以 您需要手动添加库。您可以通过直接 自述文件中A)点的说明。

    参考工作代码:

    建筑gradle(模块:应用程序):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.package_name.highchartdemo"
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
    }
    
    repositories{
        flatDir{
            dirs 'libs'
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        compile (name: 'highcharts-release', ext:'aar')
        compile 'com.google.code.gson:gson:2.8.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
    

    主要活动:

       package com.package_name.highchartdemo;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    import com.highsoft.highcharts.Core.*;
    import com.highsoft.highcharts.Common.HIChartsClasses.*;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            HIChartView chartView = (HIChartView) findViewById(R.id.hc);
    
            HIOptions options = new HIOptions();
    
            HIChart chart = new HIChart();
            chart.type = "column";
            options.chart = chart;
    
            HITitle title = new HITitle();
            title.text = "Demo chart";
    
            options.title = title;
    
            HIColumn series = new HIColumn();
            series.data = new ArrayList<>(Arrays.asList(49.9, 71.5, 106.4, 129.2, 144, 176, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
            options.series = new ArrayList<HISeries>(Collections.singletonList(series));
    
            chartView.options = options;
        }
    }
    

    activity\u main:

        <?xml version="1.0" encoding="utf-8"?>
    <com.highsoft.highcharts.Core.HIChartView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:id="@+id/hc"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.package_name.highchartdemo.MainActivity"/>