错误:(145,40)错误:找不到符号变量activity_maps

时间:2016-02-11 17:33:01

标签: android android-studio

我正在尝试在我的第二个主要活动上实施室内位置。我收到以下错误。我想按下室内导航按钮在室内有地图并在室内显示你的位置。提前谢谢

     Information:Gradle tasks [:app:assembleDebug] 
     Error:(167, 99) error: cannot find symbol variable map
     Error:(145, 40) error: cannot find symbol variable activity_maps

Main2Activity

package com.Design.Design.activity;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Looper;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlay;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.indooratlas.android.sdk.IALocation;
import com.indooratlas.android.sdk.IALocationListener;
import com.indooratlas.android.sdk.IALocationManager;
import com.indooratlas.android.sdk.IALocationRequest;
import com.indooratlas.android.sdk.IARegion;
import com.indooratlas.android.sdk.resources.IAFloorPlan;
import com.indooratlas.android.sdk.resources.IALatLng;
import com.indooratlas.android.sdk.resources.IALocationListenerSupport;
import com.indooratlas.android.sdk.resources.IAResourceManager;
import com.indooratlas.android.sdk.resources.IAResult;
import com.indooratlas.android.sdk.resources.IAResultCallback;
import com.indooratlas.android.sdk.resources.IATask;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import com.squareup.picasso.Target;

import android.os.Bundle;
import android.app.Activity;

import com.lightcurb.example.R;

public class Main2Activity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    class MapsOverlayActivity extends FragmentActivity {

        private static final String TAG = "IndoorAtlasExample";

        private static final float HUE_IABLUE = 200.0f;

        /* used to decide when bitmap should be downscaled */
        private static final int MAX_DIMENSION = 2048;

        private GoogleMap mMap; // Might be null if Google Play services APK is not available.
        private Marker mMarker;
        private GroundOverlay mGroundOverlay;
        private IALocationManager mIALocationManager;
        private IAResourceManager mResourceManager;
        private IATask<IAFloorPlan> mFetchFloorPlanTask;
        private Target mLoadTarget;
        private boolean mCameraPositionNeedsUpdating;

        /**
         * Listener that handles location change events.
         */
        private IALocationListener mListener = new IALocationListenerSupport() {

            /**
             * Location changed, move marker and camera position.
             */
            @Override
            public void onLocationChanged(IALocation location) {

                Log.d(TAG, "new location received with coordinates: " + location.getLatitude()
                        + "," + location.getLongitude());

                if (mMap == null) {
                    // location received before map is initialized, ignoring update here
                    return;
                }

                LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                if (mMarker == null) {
                    // first location, add marker
                    mMarker = mMap.addMarker(new MarkerOptions().position(latLng)
                            .icon(BitmapDescriptorFactory.defaultMarker(HUE_IABLUE)));
                } else {
                    // move existing markers position to received location
                    mMarker.setPosition(latLng);
                }

                // our camera position needs updating if location has significantly changed
                if (mCameraPositionNeedsUpdating) {
                    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.5f));
                    mCameraPositionNeedsUpdating = false;
                }
            }
        };

        /**
         * Region listener that when:
         * <ul>
         * <li>region has entered; marks need to move camera and starts
         * loading floor plan bitmap</li>
         * <li>region has existed; clears marker</li>
         * </ul>.
         */
        private IARegion.Listener mRegionListener = new IARegion.Listener() {

            @Override
            public void onEnterRegion(IARegion region) {

                if (region.getType() == IARegion.TYPE_UNKNOWN) {
                    Toast.makeText(MapsOverlayActivity.this, "Moved out of map",
                            Toast.LENGTH_LONG).show();
                    return;
                }

                // entering new region, mark need to move camera
                mCameraPositionNeedsUpdating = true;

                final String newId = region.getId();

                Toast.makeText(MapsOverlayActivity.this, newId, Toast.LENGTH_SHORT).show();
                fetchFloorPlan(newId);
            }

            @Override
            public void onExitRegion(IARegion region) {
                if (mMarker != null) {
                    mMarker.remove();
                    mMarker = null;
                }
            }

        };


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

            // prevent the screen going to sleep while app is on foreground
            findViewById(android.R.id.content).setKeepScreenOn(true);

            // instantiate IALocationManager and IAResourceManager
            mIALocationManager = IALocationManager.create(this);
            mResourceManager = IAResourceManager.create(this);
        }

        @Override
        protected void onDestroy() {
            super.onDestroy();
            // remember to clean up after ourselves
            mIALocationManager.destroy();
        }

        @Override
        protected void onResume() {
            super.onResume();
            if (mMap == null) {
                // Try to obtain the map from the SupportMapFragment.
                mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                        .getMap();
            }

            // start receiving location updates & monitor region changes
            mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mListener);
            mIALocationManager.registerRegionListener(mRegionListener);
        }

        @Override
        protected void onPause() {
            super.onPause();
            // unregister location & region changes
            mIALocationManager.removeLocationUpdates(mListener);
            mIALocationManager.registerRegionListener(mRegionListener);
        }


        /**
         * Sets bitmap of floor plan as ground overlay on Google Maps
         */
        private void setupGroundOverlay(IAFloorPlan floorPlan, Bitmap bitmap) {

            if (mGroundOverlay != null) {
                mGroundOverlay.remove();
            }

            if (mMap != null) {
                BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                IALatLng iaLatLng = floorPlan.getCenter();
                LatLng center = new LatLng(iaLatLng.latitude, iaLatLng.longitude);
                GroundOverlayOptions fpOverlay = new GroundOverlayOptions()
                        .image(bitmapDescriptor)
                        .position(center, floorPlan.getWidthMeters(), floorPlan.getHeightMeters())
                        .bearing(floorPlan.getBearing());

                mGroundOverlay = mMap.addGroundOverlay(fpOverlay);
            }
        }

        /**
         * Download floor plan using Picasso library.
         */
        private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {

            final String url = floorPlan.getUrl();

            if (mLoadTarget == null) {
                mLoadTarget = new Target() {

                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x"
                                + bitmap.getHeight());
                        setupGroundOverlay(floorPlan, bitmap);
                    }

                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) {
                        // N/A
                    }

                    @Override
                    public void onBitmapFailed(Drawable placeHolderDraweble) {
                        Toast.makeText(MapsOverlayActivity.this, "Failed to load bitmap",
                                Toast.LENGTH_SHORT).show();
                    }
                };
            }

            RequestCreator request = Picasso.with(this).load(url);

            final int bitmapWidth = floorPlan.getBitmapWidth();
            final int bitmapHeight = floorPlan.getBitmapHeight();

            if (bitmapHeight > MAX_DIMENSION) {
                request.resize(0, MAX_DIMENSION);
            } else if (bitmapWidth > MAX_DIMENSION) {
                request.resize(MAX_DIMENSION, 0);
            }

            request.into(mLoadTarget);
        }


        /**
         * Fetches floor plan data from IndoorAtlas server.
         */
        private void fetchFloorPlan(String id) {

            // if there is already running task, cancel it
            cancelPendingNetworkCalls();

            final IATask<IAFloorPlan> task = mResourceManager.fetchFloorPlanWithId(id);

            task.setCallback(new IAResultCallback<IAFloorPlan>() {

                @Override
                public void onResult(IAResult<IAFloorPlan> result) {

                    if (result.isSuccess() && result.getResult() != null) {
                        // retrieve bitmap for this floor plan metadata
                        fetchFloorPlanBitmap(result.getResult());
                    } else {
                        // ignore errors if this task was already canceled
                        if (!task.isCancelled()) {
                            // do something with error
                            Toast.makeText(MapsOverlayActivity.this,
                                    "loading floor plan failed: " + result.getError(), Toast.LENGTH_LONG)
                                    .show();
                            // remove current ground overlay
                            if (mGroundOverlay != null) {
                                mGroundOverlay.remove();
                                mGroundOverlay = null;
                            }
                        }
                    }
                }
            }, Looper.getMainLooper()); // deliver callbacks using main looper

            // keep reference to task so that it can be canceled if needed
            mFetchFloorPlanTask = task;

        }

        /**
         * Helper method to cancel current task if any.
         */
        private void cancelPendingNetworkCalls() {
            if (mFetchFloorPlanTask != null && !mFetchFloorPlanTask.isCancelled()) {
                mFetchFloorPlanTask.cancel();
            }
        }
    }
}

}

AndroidManifest          

<!-- SDK feature -->
<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name="com.Design.Design.LCExampleApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="Design"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.Design.Design.activity.MainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="Design"
        android:noHistory="true"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.indooratlas.android.sdk.API_KEY"
        android:value="c24c139a-0fd8-4072-b92d-440f1369a413" />
    <meta-data
        android:name="com.indooratlas.android.sdk.API_SECRET"
        android:value="jU)0v5VVdUGfpE69DUS!zLmqVhA1wiPNymesYonp6XSArIshOSfYKbhJP9v6zIpdl8U9hOhrgQiPWYYjwSWUjgjDlbi44MNu0P52dwglirV0qTAWFfY7sj)ClhXp80i1" />
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="309aec780906102743dd39ea4d8eddc07f46eed8" />

    <activity
        android:name="com.Design.Design.activity.Main2Activity"
        android:label="@string/title_activity_main2"></activity>
</application>

build.gradle(Module:app)

buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
compileSdkVersion 23
defaultConfig {
  applicationId "com.lightcurb.example"
  minSdkVersion 18
  targetSdkVersion 21
  versionCode 9
  versionName "1.0.0"
}
buildTypes {
  release {
     minifyEnabled false
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
   }
  buildToolsVersion '23.0.2'
  splits {
    abi {
        enable true
        reset()
        include 'x86', 'armeabi-v7a'
        universalApk true
      }
   }
}

repositories {
 mavenCentral()
 flatDir {
  dirs 'libs'
 }
  maven { url 'https://maven.fabric.io/public' }
 }

 dependencies {
 compile 'com.indooratlas.android:indooratlas-android-sdk:2.0.2-beta@aar'
 compile 'com.radiusnetworks:AndroidIBeaconLibrary:0.7.7@aar'
 compile 'com.lightcurb.sdk:LightcurbSDK:1.0.1@aar'
 compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
   } 
 }
 repositories{
  maven {
    url "http://indooratlas-ltd.bintray.com/mvn-public"
  }
 }

MainActivity:

   package com.Design.Design.activity;

     import android.app.Activity;
   import android.content.BroadcastReceiver;
   import android.content.Context;
   import android.content.Intent;
   import android.content.IntentFilter;
    import android.location.Criteria;
   import android.location.LocationManager;
   import android.graphics.Color;
    import android.os.Bundle;
   import android.widget.RelativeLayout;
      import android.widget.Button;
      import android.widget.TextView;

   import com.crashlytics.android.Crashlytics;
   import com.lightcurb.example.R;
  import com.lightcurb.sdk.api.LCAPIManager;
  import com.lightcurb.sdk.api.request.LCAPIResponse;
   import com.lightcurb.sdk.model.LCNotification;
   import io.fabric.sdk.android.Fabric;

  public class MainActivity extends Activity
  {
   private static final String TAG = MainActivity.class.getPackage() + "." +    MainActivity.class.getSimpleName();

 private TextView textView;

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  Fabric.with(this, new Crashlytics());

  setContentView(R.layout.activity_main);

    RelativeLayout StevesLayout = new RelativeLayout(this);
    StevesLayout.setBackgroundColor(Color.BLUE);

    RelativeLayout.LayoutParams buttonDetails = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT
    );

    buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL);
    buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL);

    Button NavButton = new Button(this);
    NavButton.setText("Indoor Navigation");
    NavButton.setBackgroundColor(Color.WHITE);







  NavButton.setId(1);






    StevesLayout.addView(NavButton,buttonDetails);
    setContentView(StevesLayout);

  textView = (TextView) findViewById(R.id.textView);
  Button addBtn = (Button) findViewById(R.id.button);
}

 @Override
 protected void onStart()
 {
  super.onStart();

    IntentFilter apiManagerFilter = new IntentFilter();
     apiManagerFilter.addAction(LCAPIManager.REGISTER_FOUND_BEACONS_REQUEST_STATUS_CHANGE);
    registerReceiver(apiManagerReceiver, apiManagerFilter);
  }

  @Override
   protected void onStop()
  {
    super.onStop();

    unregisterReceiver(apiManagerReceiver);
  }

  private BroadcastReceiver apiManagerReceiver = new BroadcastReceiver()
  {
   @Override
   public void onReceive(Context context, Intent intent)
   {
     Bundle extras = intent.getExtras();
     String status = extras.getString("status");
     LCAPIResponse response = extras.getParcelable("response");

     if (status.equals("finished") && response.isSuccess())
     {
        LCNotification notification = extras.getParcelable("objectdata");
        textView.setText(notification.getPromotion().getDescription());
      }
   }
  };
}

1 个答案:

答案 0 :(得分:0)

为什么要从其他软件包导入R?从您的代码中,我可以看到您从R导入com.lightcurb.example,这是一个不同的包。

因此删除,

import com.lightcurb.example.R;

来自您的进口。

请注意,您不必导入R,因为它实际上是在成功完成构建后创建的R.java文件。并且,如果您有任何错误(即R下的红色下划线),那么它表示您的项目中存在一些构建错误。如果,请检查您的xml文件,gradle文件等。