눈공원
10
2022-06-17 00:03:31 작성 2022-06-17 02:26:07 수정됨
1
82

안드로이드 JAVA, 구글 맵 레이아웃 변환 Intent 에러 관련 질문입니다! // ActivityNotFoundException


따로 구글링을 해보고, 저와 같은 사례도 있었으나 해결 방법은 안 적혀있고.. 애타는 마음으로 글 써봅니다 ㅠㅠ...


메인 액티비티에서 맵 이미지를 터치했을 때 구글 맵 API를 받아와 띄워주는 액티비티를 intent로 불러오는 코드를 작성했습니다.

헌데 매니페스트에 액티비티가 정의돼 있지 않다는 에러가 뜹니다.




위 사진에서 보이듯 매니페스트에 .Map이라는 class를 정의해 뒀고,



위 코드처럼 인텐트로 액티비티를 불러오려 했으나.. 불러와지지 않습니다.

아래 ivShop이라는 이미지를 클릭시에는 인텐트가 잘 작동하네요.


문제의 Map.class는 





이러한xml 화면을 Map.class에서 불러옵니다.. Map class의 코드 내용은 맨 아래에 적겠습니다.


LogCat 에러 내역입니다.

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.parking.sgmn/java.util.Map}; have you declared this activity in your AndroidManifest.xml?

        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2085)

        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)

        at android.app.Activity.startActivityForResult(Activity.java:5404)

        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)

        at android.app.Activity.startActivityForResult(Activity.java:5362)

        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)

        at android.app.Activity.startActivity(Activity.java:5748)

        at android.app.Activity.startActivity(Activity.java:5701)

        at com.parking.sgmn.MainActivity$1.onClick(MainActivity.java:33)

        at android.view.View.performClick(View.java:7441)

        at android.view.View.performClickInternal(View.java:7418)

        at android.view.View.access$3700(View.java:835)

        at android.view.View$PerformClick.run(View.java:28676)

        at android.os.Handler.handleCallback(Handler.java:938)

        at android.os.Handler.dispatchMessage(Handler.java:99)

        at android.os.Looper.loopOnce(Looper.java:201)

        at android.os.Looper.loop(Looper.java:288)

        at android.app.ActivityThread.main(ActivityThread.java:7839)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)



아래는 Map.class의 자바 코드입니다.

대학교 과제라 프로젝트를 빨리 완성해서 내야하는데 이 에러때매 미치겠습니다 ㅠㅠ....


package com.parking.sgmn;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
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.pedro.library.AutoPermissions;
import com.pedro.library.AutoPermissionsListener;

public class Map extends AppCompatActivity implements AutoPermissionsListener {

SupportMapFragment mapFrag;
GoogleMap map;

Marker marker;
LocationManager locationManager;
GPSListener gpsListener;
MarkerOptions myLocationMarker, eventMarker;

Circle circle;
CircleOptions circle300m;

Button btnEvent;
TextView tv; // ## 지울 예정 ##

Location mylocation;
Marker[] e_markers = new Marker[3];
double[][] eventlocation = new double[3][2]; // event 3개의 로케이션 값을 저장할 2차원 실수형 배열


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

tv = findViewById(R.id.tv); // ## 지울 예정 ##
btnEvent = findViewById(R.id.btnEvent);
mylocation = new Location("");

//ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MODE_PRIVATE);

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // 마지막 위치 받아오기
gpsListener = new GPSListener();

for(int i=0; eventlocation.length>i ; i++)
eventlocation[i][0]=0.0;

try {
MapsInitializer.initialize(this);
} catch (Exception e) {
e.printStackTrace();
}

mapFrag = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

mapFrag.getMapAsync(new OnMapReadyCallback() {
@SuppressLint("MissingPermission")
@Override
public void onMapReady(GoogleMap googleMap) {
Log.i("MyLocTest","지도 준비됨");
map = googleMap;
map.setMyLocationEnabled(true);
}
});

mapFrag.getView().setVisibility(View.GONE);

btnEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 지도 보임
btnEvent.setVisibility(View.INVISIBLE);
mapFrag.getView().setVisibility(View.VISIBLE);
realTimeLocationService();
}
});

AutoPermissions.Companion.loadAllPermissions(this, 101);
}

/*public void onMapReady(GoogleMap googleMap) { // 지도 초기화
map = googleMap;
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Request 다시 함
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MODE_PRIVATE);
} else {
map.setMyLocationEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(true); // 현재 위치
map.getUiSettings().setZoomControlsEnabled(true); // 줌 버튼
}
}*/

@SuppressLint("MissingPermission")
public void realTimeLocationService() {

try {
Location location = null;

long realTime = 5; // 5초마다 갱신
float minDistance = 0;

if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if(location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
String message = "최근 위치1 낄렵낄렵 -> Latitude : " + latitude + "\n Longitude : " + longitude; // ## 지울 예정 ##

tv.setText(message); // ## 지울 예정 ##
showCurrentLocation(latitude,longitude);
Log.i("MyLocTest", "최근 위치1 호출");

eventMaker(latitude, longitude);
}

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, realTime, minDistance, gpsListener);
//locationManager.removeUpdates(gpsListener);
//Toast.makeText(getApplicationContext(), "내 위치 1 확인 요청함", Toast.LENGTH_SHORT).show();
Log.i("MyLocTest", "requestLocationUpdates() 내 위치 1에서 호출 시작");

} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
String message = "최근 위치2 -> Latitude : " + latitude + "\n Longitude : " + longitude; // ## 지울 예정 ##

tv.setText(message); // ## 지울 예정 ##
showCurrentLocation(latitude,longitude);
Log.i("MyLocTest", "최근 위치2 호출");

eventMaker(latitude, longitude);
}

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, realTime, minDistance, gpsListener);
locationManager.removeUpdates(gpsListener);
Toast.makeText(getApplicationContext(), "내 위치 2 확인 요청함", Toast.LENGTH_SHORT).show();
Log.i("MyLocTest", "requestLocationUpdates() 내 위치 2에서 호출 시작");
}

} catch (SecurityException e) {
e.printStackTrace();
}

}

public class GPSListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
String message = "최근 위치1 -> Latitude : " + latitude + "\n Longitude : " + longitude; // ## 지울 예정 ##

tv.setText(message); // ## 지울 예정 ##
showCurrentLocation(latitude,longitude);
Log.i("MyLocText", "최근 위치 호출");

mylocation.setLatitude(latitude);
mylocation.setLongitude(longitude);

for(int i = 0 ; eventlocation.length > i ; i++ ) {

Location locationtemp = new Location("");
locationtemp.setLatitude(eventlocation[i][0]);
locationtemp.setLongitude(eventlocation[i][1]);

if(mylocation.distanceTo(locationtemp)<10) { // 10미터 이내라면
Toast.makeText(getApplicationContext(), "포인또 흭도쿠", Toast.LENGTH_SHORT).show();
e_markers[i].remove(); // 마커삭제

eventlocation[i][0]=0.0; // double 변수형에는 null 값을 대입할 수 없다. 그렇기 떄문에 0.0 값 대입
eventlocation[i][1]=0.0;

eventMaker(latitude, longitude);
}

}
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public void onProviderEnabled(@NonNull String provider) {
}

@Override
public void onProviderDisabled(@NonNull String provider) {
}
}

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onResume() {
super.onResume();

if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),"접근 권한이 없습니다.",Toast.LENGTH_SHORT).show();
return;
} else {

if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener);
locationManager.removeUpdates(gpsListener);
} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, gpsListener);
locationManager.removeUpdates(gpsListener);
}

if (map != null) {
map.setMyLocationEnabled(false);
}
Log.i("MyLocTest", "onResume에서 requestLocationUpdates() 되었습니다.");
}
}

@SuppressLint("MissingPermission")
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(gpsListener);

if(map != null) {
map.setMyLocationEnabled(false);
}
Log.i("MyLocTest", "onPause에서 removeUpdates() 되었습니다.");
}

private void showCurrentLocation(double latitude, double longitude) {
LatLng curPoint = new LatLng(latitude, longitude);
showMyLocationMarker(curPoint);
}

private void showMyLocationMarker(LatLng curPoint) {
if(myLocationMarker == null) {
myLocationMarker = new MarkerOptions();
myLocationMarker.position(curPoint);
myLocationMarker.title("최근위치\n");
myLocationMarker.snippet("*GPS로 확인한 최근위치");
myLocationMarker.icon(BitmapDescriptorFactory.fromResource((R.drawable.my_location_marker)));
marker = map.addMarker(myLocationMarker);
} else {
marker.remove();
myLocationMarker.position(curPoint);
marker = map.addMarker(myLocationMarker);
}

if (circle300m == null) {
circle300m = new CircleOptions().center(curPoint) // 원점
.radius(300) // 반지름 단위 : m
.strokeWidth(1.0f); // 선너비 0f : 선없음
circle300m.fillColor(Color.parseColor("#50DD3C77")); // 배경색
circle = map.addCircle(circle300m);

} else {
circle.remove(); // 반경삭제
circle300m.center(curPoint);
circle = map.addCircle(circle300m);
}

}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
AutoPermissions.Companion.parsePermissions(this, requestCode, permissions, this);
//Toast.makeText(this, "requestCode : "+requestCode+" permissions : "+permissions+" grantResults :"+grantResults, Toast.LENGTH_SHORT).show();
}

@Override
public void onDenied(int requestCode, String[] permissions) {
//Toast.makeText(getApplicationContext(),"permissions denied : " + permissions.length, Toast.LENGTH_SHORT).show();
}

@Override
public void onGranted(int requestCode, String[] permissions) {
//Toast.makeText(getApplicationContext(),"permissions granted : " + permissions.length, Toast.LENGTH_SHORT).show();
}

public void eventMaker(double latitude, double longitude) {

mylocation.setLatitude(latitude);
mylocation.setLongitude(longitude);

for(int i = 0; i < eventlocation.length; i++) {
if (eventlocation[i][0] == 0.0) {
double randomlat = Math.random() * 0.002, randomlng = Math.random() * 0.002; // 0.0~1.0 * 0.0001 난수 발생
double where = Math.random();

if (where > 0.75) {
eventlocation[i][0] = latitude + randomlat;
eventlocation[i][1] = longitude + randomlng;
} else if (where > 0.5) {
eventlocation[i][0] = latitude - randomlat;
eventlocation[i][1] = longitude + randomlng;
} else if (where > 0.25) {
eventlocation[i][0] = latitude + randomlat;
eventlocation[i][1] = longitude - randomlng;
} else {
eventlocation[i][0] = latitude - randomlat;
eventlocation[i][1] = longitude - randomlng;
}

LatLng latLngtemp = new LatLng(eventlocation[i][0], eventlocation[i][1]);

//Toast.makeText(getApplicationContext(), eventlocation[i][0]+", "+eventlocation[i][1]+"좌표에 이벤트 생성", Toast.LENGTH_SHORT).show();

eventMarker = new MarkerOptions();
eventMarker.position(latLngtemp);
eventMarker.title("이벤트 명\n");
eventMarker.snippet("이벤트 효과");
eventMarker.icon(BitmapDescriptorFactory.fromResource((R.drawable.event)));
e_markers[i] = map.addMarker(eventMarker);

Location locationtemp = new Location("");
locationtemp.setLatitude(eventlocation[i][0]);
locationtemp.setLongitude(eventlocation[i][1]);

if (mylocation.distanceTo(locationtemp) > 500 || mylocation.distanceTo(locationtemp) < 100) {// mylocation에서부터 locationtemp까지의 거리가 100~500 미터 내 이벤트 생성
//Toast.makeText(getApplicationContext(), "어림도없다!", Toast.LENGTH_SHORT).show();
eventlocation[i][0] = 0.0;
e_markers[i].remove();
i--;
}

map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLngtemp, 16));
Log.i("MyLocTest", "로케이션 출력!");
}
}

}
}
0
  • 답변 1

  • GAN
    2k
    2022-06-17 10:52:56

    intent 생성 시 com.parking.sgmn.Map 이 아니라 java.util.Map 을 사용하고 있는 것 같네요.

  • 로그인을 하시면 답변을 등록할 수 있습니다.