Принудительно закрыть при открытии Google Maps - PullRequest
0 голосов
/ 14 февраля 2012

Я знаю, что это были некоторые посты, у которых была такая же проблема. Я прочитал их все, хотя это не решило мою проблему. Вот мой AndroidManifest.XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.first.project"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name=".GPS"
        android:label="@string/app_name" >

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

    </activity>

    <activity android:name=".About"
              android:label="@string/about_title" />
    <activity android:name=".getGPS"
              android:label="@string/get_gps" />
</application>
</manifest>

Вот XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/id1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My text edit this."
/>
<com.google.android.maps.MapView
android:id="@+id/myGMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0VeISgtB_USJi-BUVme-Zmbo7st7ED2Pf3TAv**"
/>
</LinearLayout>

А вот и журнал:

02-14 20:53:06.077: E/AndroidRuntime(302): FATAL EXCEPTION: main
02-14 20:53:06.077: E/AndroidRuntime(302): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.first.project/my.first.project.getGPS}: android.view.InflateException: Binary XML file line #12: Error inflating class com.google.android.maps.MapView
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.os.Looper.loop(Looper.java:123)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-14 20:53:06.077: E/AndroidRuntime(302):  at java.lang.reflect.Method.invokeNative(Native Method)
02-14 20:53:06.077: E/AndroidRuntime(302):  at java.lang.reflect.Method.invoke(Method.java:521)
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-14 20:53:06.077: E/AndroidRuntime(302):  at dalvik.system.NativeStart.main(Native Method)
02-14 20:53:06.077: E/AndroidRuntime(302): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.google.android.maps.MapView
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.Activity.setContentView(Activity.java:1647)
02-14 20:53:06.077: E/AndroidRuntime(302):  at my.first.project.getGPS.onCreate(getGPS.java:45)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-14 20:53:06.077: E/AndroidRuntime(302):  ... 11 more
02-14 20:53:06.077: E/AndroidRuntime(302): Caused by: java.lang.reflect.InvocationTargetException
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.google.android.maps.MapView.<init>(MapView.java:238)
02-14 20:53:06.077: E/AndroidRuntime(302):  at java.lang.reflect.Constructor.constructNative(Native Method)
02-14 20:53:06.077: E/AndroidRuntime(302):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-14 20:53:06.077: E/AndroidRuntime(302):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
02-14 20:53:06.077: E/AndroidRuntime(302):  ... 21 more
02-14 20:53:06.077: E/AndroidRuntime(302): Caused by: java.lang.NullPointerException
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:382)
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.google.android.maps.MapView.<init>(MapView.java:280)
02-14 20:53:06.077: E/AndroidRuntime(302):  at com.google.android.maps.MapView.<init>(MapView.java:255)
02-14 20:53:06.077: E/AndroidRuntime(302):  ... 25 more

Я получаю предупреждение "Force Close".

Есть предложения?


public class getGPS extends MapActivity implements LocationListener 
{    
EditText txted = null;
Button btnSimple = null;
MapView gMapView = null;
MapController mc = null;
Drawable defaultMarker = null;
GeoPoint p = null;
double latitude = 10, longitude = 10;

@Override
public void onCreate(Bundle savedInstanceState)
{
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.getgps);

    // Creating TextBox displying Lat, Long
    txted = (EditText) findViewById(R.id.id1);
    String currentLocation = "Lat: " + latitude + " Lng: " + longitude;
    txted.setText(currentLocation);

    // Creating and initializing Map
    gMapView = (MapView) findViewById(R.id.myGMap);
    p = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
    gMapView.setSatellite(true);
    mc = gMapView.getController();
    mc.setCenter(p);
    mc.setZoom(14);

    // Add a location mark
    MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
    List<Overlay> list = gMapView.getOverlays();
    list.add(myLocationOverlay);

    // Adding zoom controls t o Map
    @SuppressWarnings("deprecation")
    ZoomControls zoomControls = (ZoomControls) gMapView.getZoomControls();
    zoomControls.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

    gMapView.addView(zoomControls);
    gMapView.displayZoomControls(true);

    // Getting locationManager and reflecting changes over map if distance travel by
    // user is greater than 500m from current location.
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
}

/* This method is called when use position will get changed */
public void onLocationChanged(Location location) {
    if (location != null) {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        String currentLocation = "Lat: " + lat + " Lng: " + lng;
        txted.setText(currentLocation);
        p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
        mc.animateTo(p);
    }
}

public void onProviderDisabled(String provider) {
    // required for interface, not used
}

public void onProviderEnabled(String provider) {
    // required for interface, not used
}

public void onStatusChanged(String provider, int status, Bundle extras) {
    // required for interface, not used
}

protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

/* Class overload draw method which actually plot a marker,text etc. on Map */
protected class MyLocationOverlay extends com.google.android.maps.Overlay {

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
        Paint paint = new Paint();

        super.draw(canvas, mapView, shadow);
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();
        mapView.getProjection().toPixels(p, myScreenCoords);

        paint.setStrokeWidth(1);
        paint.setARGB(255, 255, 255, 255);
        paint.setStyle(Paint.Style.STROKE);

        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);

        canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
        canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
        return true;
    }
}
}

Ответы [ 3 ]

0 голосов
/ 14 февраля 2012

В вашем AndroidManifest.XML я думаю, что вы объявляете имя несоответствия .. (class getGPS extends MapActivity, но вы объявляете android:name=".GPS")

 <activity
        android:name=".getGPS"
        android:label="@string/app_name" >

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

    </activity>

Редактировать

Убедитесь, что имя вашего класса и имя, которое вы объявляете в android:name, совпадают.

Например, если ваш класс getGPS, вы должны объявить в манифесте android:name=".getGPS" как в примере выше.

0 голосов
/ 15 февраля 2012

РЕШИТЬ!Вот источник, который мне помог:

http://code.google.com/p/androidannotations/issues/detail?id=73

Причина была в том, что я написал super.OnCreate () перед setContentView () Это должно быть так:

super.onCreate(savedInstanceState);
setContentView(R.layout.getgps);
0 голосов
/ 14 февраля 2012

вы можете попробовать карту, как это в представлении

<view android:id="@+id/mapview"
 class="com.google.android.maps.MapView"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_weight="1" 
 android:clickable="true"
 android:apiKey="key"
/> 

Я думаю, что его проблема с видом.

...