mercredi 15 octobre 2014

My application has stopped android


Vote count:

0




I'm doing a basic android application that is able to take in the GPS co-ordinates.. After compilation i am always getting a error saying my application has stopped.. Can anyone tell me why? I'm new to android Here's my codes:


GetLocationFromGPS.java



package com.example.getlocationfromgps;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.widget.TextView;

public class GetLocationFromGPS extends Activity {

TextView testViewStatus, textViewLatitude, textViewLongitude;

LocationManager myLocationManager;
String PROVIDER = LocationManager.GPS_PROVIDER;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testViewStatus = (TextView)findViewById(R.id.status);
textViewLatitude = (TextView)findViewById(R.id.latitude);
textViewLongitude = (TextView)findViewById(R.id.longitude);

myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

//get last known location, if available
Location location = myLocationManager.getLastKnownLocation(PROVIDER);
showMyLocation(location);
}

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

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myLocationManager.requestLocationUpdates(
PROVIDER, //provider
0, //minTime
0, //minDistance
myLocationListener); //LocationListener
}

private void showMyLocation(Location l){
if(l == null){
testViewStatus.setText("No Location!");
}else{
textViewLatitude.setText("Latitude: " + l.getLatitude());
textViewLongitude.setText("Longitude: " + l.getLongitude());
}

}

private LocationListener myLocationListener
= new LocationListener(){

public void onLocationChanged(Location location) {
showMyLocation(location);
}

public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}};
}


activity_main.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:id="@+id/status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/latitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/longitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

</LinearLayout>


Manifest File



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="ca.uwaterloo.Lab4_201_20"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="ca.uwaterloo.Lab4_201_20.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>
</application>

</manifest>


Logcat Error:



10-15 12:16:01.988: D/dalvikvm(1232): Late-enabling CheckJNI
10-15 12:16:02.036: D/AndroidRuntime(1232): Shutting down VM
10-15 12:16:02.036: W/dalvikvm(1232): threadid=1: thread exiting with uncaught exception (group=0xa4c4e648)
10-15 12:16:02.036: E/AndroidRuntime(1232): FATAL EXCEPTION: main
10-15 12:16:02.036: E/AndroidRuntime(1232): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.getlocationfromgps/com.example.getlocationfromgps.Main}: java.lang.ClassNotFoundException: Didn't find class "com.example.getlocationfromgps.Main" on path: DexPathList[[zip file "/data/app/com.example.getlocationfromgps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.getlocationfromgps-1, /system/lib]]
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.os.Looper.loop(Looper.java:137)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-15 12:16:02.036: E/AndroidRuntime(1232): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 12:16:02.036: E/AndroidRuntime(1232): at java.lang.reflect.Method.invoke(Method.java:525)
10-15 12:16:02.036: E/AndroidRuntime(1232): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-15 12:16:02.036: E/AndroidRuntime(1232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-15 12:16:02.036: E/AndroidRuntime(1232): at dalvik.system.NativeStart.main(Native Method)
10-15 12:16:02.036: E/AndroidRuntime(1232): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.getlocationfromgps.Main" on path: DexPathList[[zip file "/data/app/com.example.getlocationfromgps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.getlocationfromgps-1, /system/lib]]
10-15 12:16:02.036: E/AndroidRuntime(1232): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-15 12:16:02.036: E/AndroidRuntime(1232): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-15 12:16:02.036: E/AndroidRuntime(1232): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-15 12:16:02.036: E/AndroidRuntime(1232): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-15 12:16:02.036: E/AndroidRuntime(1232): ... 11 more


asked 2 mins ago


1 Answer



Vote count:

0




try to change this



<activity
android:name="com.example.getlocationfromgps.GetLocationFromGPS "
android:label="@string/app_name" >


Register your Activity in your manifest.xml



answered 1 min ago

Manish

12.2k





My application has stopped android

Aucun commentaire:

Enregistrer un commentaire