마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 네이버 맵 API사용에 대해 질문드립니다.

0 추천

제가 개인적으로 어플을 만들고있는데, 그 어플에 지도기능을 추가하고 싶습니다. 인터넷을 참고하여 소스를 짜 보았는데 에러만 발생을 하네여 ㅠㅠ

저는 구글에 나와있는대로 쳐보기도하고 나름 짱구를 굴려서 해보았지만 뭐가 문제인지 도저히 모르겠습니다.... ㅠㅠ소스와 Logcat을 봐도 모르겠어요 ㅠㅠ조언부탁드립니다.

 

package com.summer_vacation;

import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import com.example.summervacation.R;
import com.nhn.android.maps.NMapActivity;
import com.nhn.android.maps.NMapController;
import com.nhn.android.maps.NMapView;
import com.nhn.android.maps.NMapView.OnMapStateChangeListener;
import com.nhn.android.maps.NMapView.OnMapViewTouchEventListener;
import com.nhn.android.maps.maplib.NGeoPoint;
import com.nhn.android.maps.nmapmodel.NMapError;

public class MapActivity extends NMapActivity implements
		OnMapStateChangeListener, OnMapViewTouchEventListener {

	public static final String API_Key = "8c5825c0a43d9424e34e739dde5f230b";
	// 네이버 API 발급
	NMapView mMapview = null;
	NMapController mMapController = null;
	LinearLayout MapLayout;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		MapLayout = (LinearLayout) findViewById(R.id.map);
		mMapview = new NMapView(this);
		//checked
		mMapview.setApiKey(API_Key);
		//checked
		setContentView(mMapview);
		//checked
		mMapview.setClickable(true);
		//checked
		mMapview.setOnMapStateChangeListener(this);
		//checked
		mMapview.setOnMapViewTouchEventListener(this);
		//checked
		mMapController = mMapview.getMapController();
		//checked
		mMapview.setBuiltInZoomControls(true, null);
		//checked
		MapLayout.addView(mMapview);
		//checked
		setContentView(R.layout.activity_map);
		// TODO Auto-generated method stub
	}

	@Override
	public void onLongPress(NMapView arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onLongPressCanceled(NMapView arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onScroll(NMapView arg0, MotionEvent arg1, MotionEvent arg2) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onSingleTapUp(NMapView arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTouchDown(NMapView arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTouchUp(NMapView arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onAnimationStateChange(NMapView arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onMapCenterChange(NMapView arg0, NGeoPoint arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onMapCenterChangeFine(NMapView arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onMapInitHandler(NMapView mapview, NMapError errorInfo) {
		// TODO Auto-generated method stub

		if (errorInfo == null) {
			mMapController.setMapCenter(new NGeoPoint(126.978371, 37.5666091),
					11);
		} else {
			android.util.Log.e("Map",
					"onMapInitHandler : error =" + errorInfo.toString());
		}

	}

	@Override
	public void onZoomLevelChange(NMapView arg0, int arg1) {
		// TODO Auto-generated method stub

	}

}
08-26 01:17:59.373: W/dalvikvm(15128): threadid=1: thread exiting with uncaught exception (group=0x41ee8e48)
08-26 01:17:59.373: E/AndroidRuntime(15128): FATAL EXCEPTION: main
08-26 01:17:59.373: E/AndroidRuntime(15128): Process: com.example.summervacation, PID: 15128
08-26 01:17:59.373: E/AndroidRuntime(15128): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.summervacation/com.summer_vacation.MapActivity}: java.lang.NullPointerException
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread.access$800(ActivityThread.java:139)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.os.Handler.dispatchMessage(Handler.java:102)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.os.Looper.loop(Looper.java:136)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread.main(ActivityThread.java:5103)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at java.lang.reflect.Method.invoke(Method.java:515)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at dalvik.system.NativeStart.main(Native Method)
08-26 01:17:59.373: E/AndroidRuntime(15128): Caused by: java.lang.NullPointerException
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at com.summer_vacation.MapActivity.onCreate(MapActivity.java:46)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.Activity.performCreate(Activity.java:5275)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
08-26 01:17:59.373: E/AndroidRuntime(15128): 	... 11 more

 

개발하는캐미 (230 포인트) 님이 2014년 8월 26일 질문

2개의 답변

0 추천
MapActivity의 46번째 줄에서 Null Pointer 에러네요. 위에서는 어디가 46번째 줄인지 모르니 해당 부분을 찾아보세요.
인연 (31,880 포인트) 님이 2014년 8월 26일 답변
감사합니다 해보겠습니다 ~
0 추천
setContentView가 findViewById보다 앞에 있어야 뷰가 찾아지겠죠?
alkyne (22,960 포인트) 님이 2014년 8월 26일 답변
네 감사드려요 ㅠㅠ 다시 설정해보니 에러가없어졌습니다 !
...