MAPS应用程序android已停止

时间:2017-03-13 20:31:55

标签: android mysql dictionary

请帮我..    它是2个星期,我正在处理一个应用程序,但总是嘲笑我“应用程序停止”我不知道错误在哪里我检查所有代码也尝试我找到的所有解决方案..但任何结果.. !

*************** MY MAPSACTiViTY ************************

public class MapsActivity extends FragmentActivity implements   OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready  to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    // Setting OnClickEvent listener for the GoogleMap
    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latlng) {
            addMarker(latlng);
            sendToServer(latlng);
        }
    });

    // Starting locations retrieve task
    new RetrieveTask().execute();


}



// Adding marker on the GoogleMaps
private void addMarker(LatLng latlng) {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latlng);
    markerOptions.title(latlng.latitude + "," + latlng.longitude);
    mMap.addMarker(markerOptions);
}

// Invoking background thread to store the touched location in Remove MySQL  server
private void sendToServer(LatLng latlng) {
    new SaveTask().execute(latlng);
}


// Background thread to save the location in remove MySQL server
private class SaveTask extends AsyncTask<LatLng, Void, Void> {
    @Override
    protected Void doInBackground(LatLng... params) {
        String lat = Double.toString(params[0].latitude);
        String lng = Double.toString(params[0].longitude);
        String strUrl = "http://192.168.1.3:80/pfe/save.php";
        URL url = null;
        try {
            url = new URL(strUrl);

            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
                    connection.getOutputStream());

            outputStreamWriter.write("lat=" + lat + "&lng="+lng);
            outputStreamWriter.flush();
            outputStreamWriter.close();

            InputStream iStream = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new
                    InputStreamReader(iStream));

            StringBuffer sb = new StringBuffer();

            String line = "";

            while( (line = reader.readLine()) != null){
                sb.append(line);
            }

            reader.close();
            iStream.close();


        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

}




// Background task to retrieve locations from remote mysql server
private class RetrieveTask extends AsyncTask<Void, Void, String>{

    @Override
    protected String doInBackground(Void... params) {
        String strUrl = "http://192.168.1.3:80/pfe/retrieve.php";
        URL url = null;
        StringBuffer sb = new StringBuffer();
        try {
            url = new URL(strUrl);
            HttpURLConnection connection = (HttpURLConnection)  url.openConnection();
            connection.connect();
            InputStream iStream = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
            String line = "";
            while( (line = reader.readLine()) != null){
                sb.append(line);
            }

            reader.close();
            iStream.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        new ParserTask().execute(result);
    }

}

// Background thread to parse the JSON data retrieved from MySQL server
private class ParserTask extends AsyncTask<String, Void, List<HashMap<String, String>>>{
    @Override
    protected List<HashMap<String,String>> doInBackground(String... params)  {
        MarkerJSONParser markerParser = new MarkerJSONParser();
        JSONObject json = null;
        try {
            json = new JSONObject(params[0]);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        List<HashMap<String, String>> markersList =  markerParser.parse(json);
        return markersList;
    }

    @Override
    protected void onPostExecute(List<HashMap<String, String>> result) {
        for(int i=0; i<result.size();i++){
            HashMap<String, String> marker = result.get(i);
            LatLng latlng = new  LatLng(Double.parseDouble(marker.get("lat")), Double.parseDouble(marker.get("lng")));
            addMarker(latlng);
        }
    }
}

@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;
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the  camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in  Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

}
}

**************************** JASONCODE ****************** ********

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
* Created by chaima on 13/03/2017.
*/

public class MarkerJSONParser {

    /** Receives a JSONObject and returns a list */
    public List<HashMap<String,String>> parse(JSONObject jObject){

        JSONArray jMarkers = null;
        try {
            /** Retrieves all the elements in the 'markers' array */
            jMarkers = jObject.getJSONArray("markers");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /** Invoking getMarkers with the array of json object
         * where each json object represent a marker
         */
        return getMarkers(jMarkers);
    }


    private List<HashMap<String, String>> getMarkers(JSONArray jMarkers){
        int markersCount = jMarkers.length();
        List<HashMap<String, String>> markersList = new  ArrayList<HashMap<String,String>>();
        HashMap<String, String> marker = null;

        /** Taking each marker, parses and adds to list object */
        for(int i=0; i<markersCount;i++){
            try {
                /** Call getMarker with marker JSON object to parse the  marker */
                marker = getMarker((JSONObject)jMarkers.get(i));
                markersList.add(marker);
            }catch (JSONException e){
                e.printStackTrace();
            }
        }

        return markersList;
    }

    /** Parsing the Marker JSON object */
    private HashMap<String, String> getMarker(JSONObject jMarker){

        HashMap<String, String> marker = new HashMap<String, String>();
        String lat = "-NA-";
        String lng ="-NA-";


        try {
            // Extracting latitude, if available
            if(!jMarker.isNull("lat")){
                lat = jMarker.getString("lat");
            }

            // Extracting longitude, if available
            if(!jMarker.isNull("lng")){
                lng = jMarker.getString("lng");
            }

            marker.put("lat", lat);
            marker.put("lng", lng);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return marker;
    }
}

************************ Gridle ******************

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.chaima.myapplicationpfe"
    minSdkVersion 18
    targetSdkVersion 25
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner  "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',  {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.android.gms:play-services:10.2.0'
testCompile 'junit:junit:4.12'
}


************************MANIFEST*******************
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chaima.myapplicationpfe">

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--
         The API key for Google Maps-based APIs is defined as a string   resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign  the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <uses-library android:name="com.google.android.maps" />

</application>

</manifest>

************************** XML ****************

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.chaima.myapplicationpfe.MapsActivity" />

********* ********* LOGCATE *******

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.example.chaima.myapplicationpfe, PID: 1330
                                                                                java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.chaima.myapplicationpfe-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.chaima.myapplicationpfe-1, /vendor/lib, /system/lib]]
                                                                                   at android.app.ActivityThread.installProvider(ActivityThread.java:5018)
                                                                                   at android.app.ActivityThread.installContentProviders(ActivityThread.java:4589)
                                                                                   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
                                                                                   at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                   at android.os.Looper.loop(Looper.java:193)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5299)
                                                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
                                                                                   at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.chaima.myapplicationpfe-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.chaima.myapplicationpfe-1, /vendor/lib, /system/lib]]
                                                                                   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                   at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
                                                                                   at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
                                                                                   at android.app.ActivityThread.installProvider(ActivityThread.java:5003)
                                                                                   at android.app.ActivityThread.installContentProviders(ActivityThread.java:4589) 
                                                                                   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522) 
                                                                                   at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                   at android.os.Looper.loop(Looper.java:193) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5299) 
                                                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                   at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) 
                                                                                   at dalvik.system.NativeStart.main(Native Method) 

0 个答案:

没有答案