java - API key 配置android

标签 java android api themoviedb-api

在我的应用程序中,我将使用 The Movies DB API 来获取最受欢迎的电影海报。

请您帮助解决以下问题:

每次我尝试运行我的应用程序时都会收到这些错误

错误:(14, 77) 错误:预期

错误:(14, 53) 错误:“;”预计

错误:(14, 45) 错误:浮点文字格式错误

apply plugin: 'com.android.application'


  android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.almaneakhaled.popularmoviesapp2"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    buildTypes.each {
        it.buildConfigField 'String', 'THE_MOVIE_DB', '967888xxxxxxxxx'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
 }

这是我在 buildconfig.java 中收到错误的地方:

这里的顶部有一行说“构建文件夹下的文件是生成的,不应编辑”

 package com.almaneakhaled.popularmoviesapp2;

 public final class BuildConfig {
 public static final boolean DEBUG = Boolean.parseBoolean("true");
 public static final String APPLICATION_ID =      "com.almaneakhaled.popularmoviesapp2";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
 public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  // Fields from build type: debug
  public static final String THE_MOVIE_DB = 967888xxxxxxxxx;// this line is causing the issue
}

最佳答案

你应该使用反斜杠,改变

it.buildConfigField 'String', 'THE_MOVIE_DB', '967888xxxxxxxxx'

it.buildConfigField 'String', 'THE_MOVIE_DB', "\"967888xxxxxxxxx\""

关于java - API key 配置android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36118995/

相关文章:

java - 如何使用 DAO 在 Spring Boot 查询中返回特定对象属性?

javascript - 向我自己的 API 发送请求以更改未更新的数据库。我想更新数据库

python - YouTube API : How do I specify latest protocol version when using `gdata` in Python?

java - 在特定情况下如何使 JRadioButton 透明?

java - SQLite 数据库表更新除一个字段之外的所有字段

android - 如何在 Eclipse android 中启动 ADB?

android - NFC 阅读器可以从手机读取 IMEI 吗?

java - android异步读取usb

java - 如何为区域设置名称创建本地化字符串?

java - 按存在的数字对文本文件的行进行排序,并按降序输出整行