Starting with Android Google Maps API V2 - android

I am newbie on Android Google Maps API and I was trying to develop a small app using the API. I use as a reference the Google documentation form: https://developers.google.com/maps/documentation/android/ and I follow all the step with caution. When I build it and install it on to my device (Android 2.3.6) the app crash. I follow all the instructions to sign the app and get the API key for this specific app, tried all the step of the documentation several times without any good results. Please, can someone help me with this? I there something missing?
Thank you!
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.uprm_map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<permission
android:name="com.application.uprm_map.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.application.uprm_map.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.uprm_map.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="<my own key>"/>
</application>
</manifest>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
MainActivity.java
package com.application.uprm_map;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Exeptions:
03-05 02:29:27.645: D/dalvikvm(32056): GC_EXTERNAL_ALLOC freed 42K, 49% free 2748K/5379K, external 0K/0K, paused 21ms
03-05 02:29:27.650: D/AndroidRuntime(32056): Shutting down VM
03-05 02:29:27.650: W/dalvikvm(32056): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
03-05 02:29:27.655: E/AndroidRuntime(32056): FATAL EXCEPTION: main
03-05 02:29:27.655: E/AndroidRuntime(32056): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.uprm_map/com.application.uprm_map.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Looper.loop(Looper.java:130)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.NativeStart.main(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:234)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Activity.setContentView(Activity.java:1679)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.application.uprm_map.MainActivity.onCreate(MainActivity.java:11)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 11 more
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.application.uprm_map-1.apk]
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 19 more
03-05 02:29:29.660: I/dalvikvm(32056): threadid=4: reacting to signal 3
03-05 02:29:29.665: I/dalvikvm(32056): Wrote stack traces to '/data/anr/traces.txt'

First thing as you are having the API level 8 or below so you have to use the SupportMapFragment instead of MapFragment as below in your layout file.
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Second thing you have to extend the FragmentActivity instead of Activity :
public class MainActivity extends FragmentActivity {
Do the above changes and then run your application.

Related

Error in a simple hello world android program

I just created a simple hello world program, all codes are fine it seems, but something makes the android to show "unfortunately app needs to close" error
the startingPoint.java code which is the launcher class
package demo4;
import com.example.demo4.R;
import android.app.Activity;
import android.os.Bundle;
public class startingPoint extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the main.xml which is the layout for launcher class
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
the androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".startingPoint"
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>
and this is the logcat
08-30 12:46:22.921: D/AndroidRuntime(326): Shutting down VM
08-30 12:46:22.941: W/dalvikvm(326): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-30 12:46:23.021: E/AndroidRuntime(326): FATAL EXCEPTION: main
08-30 12:46:23.021: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demo4/com.example.demo4.startingPoint}: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Looper.loop(Looper.java:123)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invokeNative(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invoke(Method.java:507)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.NativeStart.main(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): Caused by: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
08-30 12:46:23.021: E/AndroidRuntime(326): ... 11 more
So I post my comment as an answer :)
It seems that android try to find the class in your package com.example.demo4.startingPoint, but in your code the package is just demo4. Try to change the first line by package com.example.demo4.
Resloved...it was as indicated by Mtoypc. the package name was different and it was not reflected in the startingPoint.java

add google maps in an android application

I'm new in Android development. I want to add Google maps to my application. I have done lots of searches but still the same problem arises when I run the application "Unfortunately , application has stopped"
So this is my java class
package com.example.hellomap;
import com.google.android.maps.MapView;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_main);
MapView map =(MapView) findViewById(R.id.map);
}
}
the xml file :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
and the Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellomap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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_GSERVICES"/>
<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" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name="com.example.hellomap.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="AIzaSyCKSp9pb7g8Wkga2SgeoT_MSe0JG59DkSU" />
</application>
</manifest>
The LogCat shows:
04-03 13:45:42.574: E/AndroidRuntime(1164): FATAL EXCEPTION: main
04-03 13:45:42.574: E/AndroidRuntime(1164): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellomap/com.example.hellomap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.os.Looper.loop(Looper.java:137)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.reflect.Method.invoke(Method.java:511)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-03 13:45:42.574: E/AndroidRuntime(1164): at dalvik.system.NativeStart.main(Native Method)
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.setContentView(Activity.java:1867)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.example.hellomap.MainActivity.onCreate(MainActivity.java:23)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.performCreate(Activity.java:5008)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 11 more
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:584)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:552)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.onCreateView(Activity.java:4656)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 20 more
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:574)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 23 more
04-03 13:50:42.626: I/Process(1164): Sending signal. PID: 1164 SIG: 9
Thanks for help :)
EXCEPTION :- ClassNotFoundException
please check GooglePlayService Library Project First.
Second Thing You Can Not Type Cast Fragment To Map View, please read this
Update:-
Follow The Step:-
1)Create New Project
2)Import GooglePlayService Library project into Your Workspace.
3)assign Google play Service library project as library project to your project
4)now add Map Fragment/Supported Map Fragment into your activity layout file
5)make sure this class found
how to check==>press control Key from keyboard and click on class name id you found class then it's okay other wise fix it first.
i prefer to use Supported Fragment.
6)define all permission as describe in link i posted previously.
6)now its time to generate api key for map ,follow the step from given link.
Thanks i hope its help

android lockscreen settext application crash

i have used a code similar to one of stackoverflow links:
how to change system alarm setting text dynamic
to only settext on the lock screen but my application crashes when i run it, any idea what i'm missing?
my mainactivty:
package l.a;
import java.net.ContentHandler;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
public class LockscreenActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context= getApplicationContext();
KeyguardManager _guard = (KeyguardManager)
context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock _keyguardLock = _guard.newKeyguardLock("KeyguardLockWrapper");
//to disable
_keyguardLock.disableKeyguard();
String message ="New alarm :";
Settings.System.putString(this.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED, message);
//to enable
_keyguardLock.reenableKeyguard();
}
}
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="l.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LockscreenActivity"
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>
the logcat:
04-03 16:43:53.920: D/AndroidRuntime(486): Shutting down VM
04-03 16:43:53.928: W/dalvikvm(486): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-03 16:43:53.968: E/AndroidRuntime(486): Uncaught handler: thread main exiting due to uncaught exception
04-03 16:43:54.138: E/AndroidRuntime(486): java.lang.RuntimeException: Unable to start activity ComponentInfo{l.a/l.a.LockscreenActivity}: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=486, uid=10040 requires android.permission.WRITE_SETTINGS
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Looper.loop(Looper.java:123)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-03 16:43:54.138: E/AndroidRuntime(486): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 16:43:54.138: E/AndroidRuntime(486): at java.lang.reflect.Method.invoke(Method.java:521)
04-03 16:43:54.138: E/AndroidRuntime(486): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-03 16:43:54.138: E/AndroidRuntime(486): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-03 16:43:54.138: E/AndroidRuntime(486): at dalvik.system.NativeStart.main(Native Method)
04-03 16:43:54.138: E/AndroidRuntime(486): Caused by: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=486, uid=10040 requires android.permission.WRITE_SETTINGS
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Parcel.readException(Parcel.java:1218)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:445)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.content.ContentResolver.insert(ContentResolver.java:629)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.provider.Settings$NameValueTable.putString(Settings.java:464)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.provider.Settings$System.putString(Settings.java:591)
04-03 16:43:54.138: E/AndroidRuntime(486): at l.a.LockscreenActivity.onCreate(LockscreenActivity.java:43)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-03 16:43:54.138: E/AndroidRuntime(486): ... 11 more
well by simply reading the logcat i found this: requires android.permission.WRITE_SETTINGS at the end of the 4th line.

Android - exception launching project on start after copying a lot of code over from another project

am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app

Impossible to instantiate an OsmDroid MapView

I'm trying to use OSMdroid for a project, and i'm utterly unable to make the simplest code work.
Well, a few days ago i was able to display maps and so on, and now i can't even instantiate a MapView.
I reduced the code to its sipmlest form.
I work with eclipse. I downloaded osmdroid-android-3.0.5.jar and slf4j-android-1.5.8.jar, and i included them in the project by adding lines to the classpath file
<classpathentry kind="lib" path="lib/osmdroid-android-3.0.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-android-1.5.8.jar"/>
Or by right clicking on them then Build Path-> Add to build path (both gave the same result, anyway)
Then i typed this code:
import android.app.Activity;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.os.Bundle;
public class TestMapActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mv=new MapView(this,256);
}
}
And i get a bug when running it on the emulator:
04-17 09:10:31.181: E/AndroidRuntime(595): FATAL EXCEPTION: main
04-17 09:10:31.181: E/AndroidRuntime(595): java.lang.NoClassDefFoundError: org.osmdroid.views.MapView
04-17 09:10:31.181: E/AndroidRuntime(595): at testmap.sagem.TestMapActivity.onCreate(TestMapActivity.java:17)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Activity.performCreate(Activity.java:4465)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Looper.loop(Looper.java:137)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 09:10:31.181: E/AndroidRuntime(595): at dalvik.system.NativeStart.main(Native Method)
When i comment out the "MapView mv=new MapView(this,256);" it works, so i don't understand why the mapview can't be instantiated.
Any idea on this?
Thank you for your attention.
EDIT:
The AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testmap.sagem"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TestMapActivity"
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>
The main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
Change Folder name "lib" to "libs" and put all jar files in that folder and Charge path of jar
files to "libs" folder. I am not sure but I think it will work.
Try to use the 3.0.7 and clean the project.
Let me know.
http://code.google.com/p/osmdroid/downloads/list

Categories

Resources