无法解析 Android Studio 上的符号“android”

2024-01-12

我一直在制作一个显示 MapView 的应用程序,它已经构建完毕,我什至在我的设备上使用它 现在我想添加更多功能,但工作室突然给出错误“无法解析符号‘android’。”...!!!!

我将工作室更新到 0.8.6(最新)..但是该死的..!!没有什么变化 ..

Errors :

package com.androidhive.googleplacesandmaps;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class PlacesMapActivity extends MapActivity {
    // Nearest places
    PlacesList nearPlaces;

    // Map view
    MapView mapView;

    // Map overlay items
    List<Overlay> mapOverlays;

    AddItemizedOverlay itemizedOverlay;

    GeoPoint geoPoint;
    // Map controllers
    MapController mc;

    double latitude;
    double longitude;
    OverlayItem overlayitem;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_places);

        // Getting intent data
        Intent i = getIntent();

        // Users current geo location
        String user_latitude = i.getStringExtra("user_latitude");
        String user_longitude = i.getStringExtra("user_longitude");

        // Nearplaces list
        nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        mapOverlays = mapView.getOverlays();

        // Geopoint to place on map
        geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
                (int) (Double.parseDouble(user_longitude) * 1E6));

        // Drawable marker icon
        Drawable drawable_user = this.getResources()
                .getDrawable(R.drawable.mark_red);

        itemizedOverlay = new AddItemizedOverlay(drawable_user, this);

        // Map overlay item
        overlayitem = new OverlayItem(geoPoint, "Your Location",
                "That is you!");

        itemizedOverlay.addOverlay(overlayitem);

        mapOverlays.add(itemizedOverlay);
        itemizedOverlay.populateNow();

        // Drawable marker icon
        Drawable drawable = this.getResources()
                .getDrawable(R.drawable.mark_blue);

        itemizedOverlay = new AddItemizedOverlay(drawable, this);

        mc = mapView.getController();

        // These values are used to get map boundary area
        // The area where you can see all the markers on screen
        int minLat = Integer.MAX_VALUE;
        int minLong = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int maxLong = Integer.MIN_VALUE;

        // check for null in case it is null
        if (nearPlaces.results != null) {
            // loop through all the places
            for (Place place : nearPlaces.results) {
                latitude = place.geometry.location.lat; // latitude
                longitude = place.geometry.location.lng; // longitude

                // Geopoint to place on map
                geoPoint = new GeoPoint((int) (latitude * 1E6),
                        (int) (longitude * 1E6));

                // Map overlay item
                overlayitem = new OverlayItem(geoPoint, place.name,
                        place.vicinity);

                itemizedOverlay.addOverlay(overlayitem);


                // calculating map boundary area
                minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
                minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
                maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
                maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
            }
            mapOverlays.add(itemizedOverlay);

            // showing all overlay items
            itemizedOverlay.populateNow();
        }

        // Adjusting the zoom level so that you can see all the markers on map
        mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

        // Showing the center of the map
        mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
        mapView.postInvalidate();

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}

构建.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        compile 'com.google.android.gms:play-services:5.0.77'
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'android'

dependencies {

    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 12
    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

}

请帮忙 .. 提前致谢


建议使用新的 Maps v2 API。

要使用它,请将以下依赖项添加到您的build.gradle:

compile 'com.google.android.gms:play-services:5.0.77'

然后按照 Google 的指南进行设置。你可以在这里找到它 https://developers.google.com/maps/documentation/android/

编辑:详细说明build.gradle文件,这是我的样子。

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '20'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'

        applicationId '<package_name>'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            runProguard false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.android.support:support-annotations:+'
    compile 'com.google.android.gms:play-services:5.0.77'
}

重要的提示:有两个build.gradle每个项目中的文件。将其放入相应模块文件夹内的文件夹中。该模块通常被称为app,如果您还没有重命名它。

添加后,请确保单击Sync Project with Gradle Files按钮位于顶部,因此它将下载所需的依赖项

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法解析 Android Studio 上的符号“android” 的相关文章

随机推荐

  • 路径存在的 MVC 路由

    我正在尝试创建一条路线 为网址添加标题 例如 http mysite com tech 但我的站点下还有一个实际目录 tech 其中包含其他静态资源 不是我的设计选择 但我正在将旧站点迁移到 mvc 并且不想破坏一堆非常旧的链接 我的路线似
  • t.replace 不是一个函数(…)trim

    当我签入 console log 并打破它时 以下内容在问题中产生错误 var map L map map setView 0 0 2 Now this should look something like Australia 2006 2
  • 用于匹配多语言号码的正则表达式不检测中文号码

    我有一个方法可以检测字符串是否是数字 public static boolean isNumber String num return num matches p N 上述方法可以成功匹配英文 印地文 阿拉伯数字 但无法匹配中文数字 三万零
  • javascript中将数组拼接成数组的更好方法

    有没有比这更好的方法在javascript中将一个数组拼接到另一个数组中 var string theArray splice start number newItemsArray join eval string 您可以使用apply h
  • Pandas:将日期划分为 30 分钟间隔并计算平均值

    我有一个带有两列的 Pandas 数据框 它们是speed and time speed date 54 72 1 33 56 49 37 1 33 59 37 03 1 34 03 24 02 7 39 58 28 02 7 40 01
  • python heapq 合并的内部工作。如何在不生成列表的情况下对列表进行排序

    如何heapq merge 即使不生成列表也可以对列表进行排序 不确定我说清楚了没有 所以 这是从leetcode 的超级丑数问题 https leetcode com problems super ugly number 和这个Pytho
  • 涉及动态字段的数据库结构

    我正在做一个项目 它主要是为了学习目的 我发现实际上尝试一个复杂的项目是掌握基础知识后学习语言的最佳方法 数据库设计不是强项 我开始阅读它 但它还处于早期阶段 我仍在学习 这是我的 alpha 模式 我真的只是想记下我能想到的所有内容 看看
  • 通过 IMAP 添加自定义 RFC822 标头?

    有没有一种简单的方法可以使用 imaplib 将自定义 RFC822 标头添加到 IMAP 服务器上的邮件中 我正在编写一个基于 python 的程序来过滤我的 IMAP 邮件存储 当我使用 Procmail 执行此操作时 我可以选择添加标
  • 如何在 ASP.NET MVC 身份上设置自定义身份验证?

    我需要的 我有一个 ASP NET 身份系统设置并使用外部登录运行 无论出于何种原因 我需要在 ASP NET 身份验证之后设置自定义身份验证 让我解释一下如何 假设我有三个页面供用户在我的应用程序上查看 页面 A B C 谁可以查看页面
  • docker-compose - ADD 失败:构建上下文之外的禁止路径

    我有这样的文件夹结构 project config docker Dockerfile docker compose yml src here is code requirements txt Dockerfile FROM python
  • React:TypeError:尝试使用react-bootstrap容器时无法读取null的属性(读取'useContext')

    正如标题中所述 我正在尝试创建一个布局组件 但使用任何react bootstrap组件似乎都会给我错误 在这种情况下 使用我收到错误 类型错误 无法读取 null 的属性 读取 useContext 该布局组件的代码如下 import R
  • awk中的浮点计算

    我对以下行为感到惊讶awk表演时浮点计算 这导致我对表数据的计算错误 awk BEGIN print 2 3 0 1 23 lt Ok awk BEGIN print int 2 3 0 1 22 lt Wrong awk BEGIN pr
  • 使用 NSLocalizedString 的最佳实践

    我 像所有其他人一样 使用NSLocalizedString本地化我的应用程序 不幸的是 有几个 缺点 不一定是 NSLocalizedString 本身的错误 包括 Xcode 中的字符串没有自动补全功能 这使得工作不仅容易出错 而且令人
  • Java找不到主类

    我编写了以下 Java 源文件 Hello java package com public class Hello public static void main String args System out println Hello 我
  • Int32.ToString() 是否特定于区域性?

    我正在运行 ReSharper 的 Beta 版本 它向我发出以下代码的警告 int id DoSomethingWith id ToString 警告位于id ToString 调用 它告诉我 明确指定字符串转换中的区域性 我理解这个警告
  • Tomcat 5.5 中的永久 301 重定向

    是否可以使用独立运行的 Tomcat 5 5 而不是在 IIS Apache 后面 进行 301 重定向 没有一种方法可以像使用 Apache 那样轻松地进行设置 最接近的方法是创建一个 servlet 或 jsp 来处理重定向 然后将其映
  • 时间间隔的 NSPredicate

    我有一张表 其中有 4 个字段 开始日期 结束日期 开始时间和结束时间 我需要设置谓词类似 if startdate lt currentdate and currentdate lt enddate if starttime lt cur
  • 如何在 Xcode 4.4 中将部署目标从 iOS 5.1 更改为 4.2

    我试图在 Xcode 4 4 中将部署目标从 5 1 更改为 4 2 但它不起作用 我下载了 4 1 4 2 的调试支持 我将架构设置为armv6 armv7 我在plist中设置了armv6 armv7 我不使用故事板 It s a 已知
  • 大型列表上单击事件的 jQuery 委托性能 - 如果动态添加更多元素,速度会变慢?

    我有一个像这样的项目的可视列表 http jsfiddle net viatropos XCe3T 1 http jsfiddle net viatropos XCe3T 1 在真实的应用程序中 我总共只加载 200 个项目 但问题是cli
  • 无法解析 Android Studio 上的符号“android”

    我一直在制作一个显示 MapView 的应用程序 它已经构建完毕 我什至在我的设备上使用它 现在我想添加更多功能 但工作室突然给出错误 无法解析符号 android 我将工作室更新到 0 8 6 最新 但是该死的 没有什么变化 Errors