PDA

View Full Version : مشکل این کد چیه ؟؟؟؟



majid.ostadi
دوشنبه 24 آذر 1393, 18:33 عصر
با سلام دووستان
اگه میشه یه راهنمایی کوچیک بکنین که مشکل این کد کجاست؟
کد مربوط به استفاده از گوگل مپ می باشد اما برنامه کرش میکنه و فورس کلوز میده
Logcat و منیفست و اکتیوتی رو گذاشتم خواهشا یه نگاهی بهش بندازین


logCat :


126611

main activity



import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUt il;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends FragmentActivity
{

private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
MapView mMapView;


@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

if (servicesOK())
{
setContentView(R.layout.activity_map);

if (initMap())
{
Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show();
}
}
else
{
setContentView(R.layout.activity_main);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

public boolean servicesOK()
{
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailab le(this);

if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}
else if (GooglePlayServicesUtil.isUserRecoverableError(isA vailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else {
Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
}
return false;
}

@Override
protected void onDestroy()
{
// TODO Auto-generated method stub
super.onDestroy();
mMapView.onDestroy();
}

@Override
public void onLowMemory()
{
// TODO Auto-generated method stub
super.onLowMemory();
mMapView.onLowMemory();
}

@Override
protected void onPause()
{
// TODO Auto-generated method stub
super.onPause();
mMapView.onPause();
}

@Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
mMapView.onResume();
}

@Override
protected void onSaveInstanceState(Bundle outState)
{
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}

private boolean initMap()
{
if(mMap == null)
{
SupportMapFragment mapFrag =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id. map);
mMap = mapFrag.getMap();
}
return (mMap != null);
}

}


Manifest



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

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

<permission
android:name="com.MAJID.usingmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

<uses-permission android:name="com.MAJID.usingmap.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_G SERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>


<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.MAJID.usingmap.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCfdWMKBqNMoGu3nbNIuq-LdTUAFEgVSyI"/>

</application>

</manifest>


Layouts :



<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="40.760586"
map:cameraTargetLng="-73.980138"
map:cameraZoom="15"
map:uiRotateGestures="false"
map:uiTiltGestures="false"
map:uiScrollGestures="false"
map:uiZoomGestures="false"
map:uiZoomControls="false"
map:mapType="terrain"
/>