안드로이드 개발 질문/답변
(글 수 45,052)
콘솔 창엔 이렇게 뜨네요
Preferred AVD 'test' is not compatible with the project target 'Google APIs'. Looking for a compatible AVD...
이게 첫번째 액티비티에서 버튼 누르면 나오는 두번째 액티 비티인데...
그런게 문제가 될수도 있을까요?
이 코드 그대로 액티비티 하나로 돌리면 잘 되는데 이건 왜 안되는지를 모르겠습니다.ㅜㅜ
제발좀 도와주세요
그리고 로그캣은..
06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2768) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread.access$2500(ActivityThread.java:129) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.os.Handler.dispatchMessage(Handler.java:99) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.os.Looper.loop(Looper.java:143) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread.main(ActivityThread.java:4732) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at java.lang.reflect.Method.invokeNative(Native Method) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at java.lang.reflect.Method.invoke(Method.java:521) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at dalvik.system.NativeStart.main(Native Method) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): Caused by: java.lang.NullPointerException 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at test.Smart_guide.guide.onCreate(guide.java:32) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2732) 06-18 01:33:57.178: ERROR/AndroidRuntime(18578): ... 11 more
소스 코드는
package test.Smart_guide;
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 android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView;
public class guide extends MapActivity implements LocationListener {
MapController mapControl;
MapView map;
LocationManager locationMgr = null;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
map = (MapView)findViewById(R.id.map_view);
mapControl = map.getController();
locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.NO_REQUIREMENT);
criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
locationMgr.requestLocationUpdates("gps", 1000, 0, guide.this);
}
@Override
public void onLocationChanged(Location location){
double lat = location.getLatitude();
double lon = location.getLongitude();
GeoPoint newPoint = new GeoPoint((int)(lat * 1E6), (int)(lon*1E6));
mapControl.animateTo(newPoint);
mapControl.setZoom(18);
MapView.LayoutParams mapMarkerParams = new MapView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, newPoint,
MapView.LayoutParams.TOP_LEFT);
ImageView mapMarker = new ImageView(getApplicationContext());
mapMarker.setImageResource(R.drawable.mark);
map.addView(mapMarker, mapMarkerParams);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
첫번째 액티 비티
public class Smart_guide extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button guide = (Button) findViewById(R.id.guide);
guide.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Smart_guide.this, guide.class);
startActivity(intent);
}
});
Button search = (Button) findViewById(R.id.search);
search.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Smart_guide.this, search.class);
startActivity(intent);
}
});
}
}




06-1801:33:57.178: ERROR/AndroidRuntime(18578): Caused by: java.lang.NullPointerException06-1801:33:57.178: ERROR/AndroidRuntime(18578): at test.Smart_guide.guide.onCreate(guide.java:32)Exception 내용을 보시면, guide.java의 32번째 줄에서 NullPointerException이 발생하고 있네요.정확히 줄 수가 안보여서 알 수 없지만 아마도map = (MapView)findViewById(R.id.map_view); 에서 값을 못가져와서 map이 null이 아닌가 싶네요..