I having trouble accessing to strings.xml:
Log.i("url",context.getString(R.string.url));
in strings.xml
<string name="url">http://myip.com/</string>
It generates a exception:
12-12 14:52:44.551: E/AndroidRuntime(3534): FATAL EXCEPTION: WebViewCoreThread
12-12 14:52:44.551: E/AndroidRuntime(3534): java.lang.NullPointerException
12-12 14:52:44.551: E/AndroidRuntime(3534): at com.usualbike.cbike.NewIncidence.noRegInsertData(NewIncidence.java:70)
12-12 14:52:44.551: E/AndroidRuntime(3534): at com.usualbike.cbike.IncidenceData$MyJavaScriptInterface.enviarIncidencia(IncidenceData.java:163)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore.access$3300(WebViewCore.java:52)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1150)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.os.Looper.loop(Looper.java:123)
12-12 14:52:44.551: E/AndroidRuntime(3534): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
12-12 14:52:44.551: E/AndroidRuntime(3534): at java.lang.Thread.run(Thread.java:1096)
try as to get String from Strings.xml
String strurl=context.getresources().getString(R.string.url);
Log.i("url ",strurl);
context is null, apparently, if you are getting a NullPointerException on that line.
Related
I just loaded my app created by cocos2dx-3.10 and when I open with it an AVD (again I haven't done any modifications to the app) the app crashes and gives the error: Unfortunately, libcocos2dx has crashed.
here is what I get in my android Monitor:
03-05 18:34:56.668 1435-1435/? D/dalvikvm: Not late-enabling CheckJNI (already on)
03-05 18:34:56.989 1435-1435/com.trying.name E/Trace: error opening trace file: No such file or directory (2)
03-05 18:34:57.419 1435-1435/com.trying.name D/AndroidRuntime: Shutting down VM
03-05 18:34:57.419 1435-1435/com.trying.name W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2f2b288)
03-05 18:34:57.518 1435-1435/com.trying.name E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-05 18:35:11.559 1435-1435/? I/Process: Sending signal. PID: 1435 SIG: 9
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.map.googlemapv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="com.map.googlemapv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.map.googlemapv2.permission.MAPS_RECEIVE" />
<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.map.googlemapv2.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="AIzaSyXXXXXXXXXXXXXXXXXXXXXXXX" />
</application>
</manifest>
Layout File
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/btnSurrey" />
</RelativeLayout>
StackTrace :
12-12 06:19:45.460: D/AndroidRuntime(907): Shutting down VM
12-12 06:19:45.460: W/dalvikvm(907): threadid=1: thread exiting with uncaught exception (group=0xb4aeab90)
12-12 06:19:45.500: E/AndroidRuntime(907): FATAL EXCEPTION: main
12-12 06:19:45.500: E/AndroidRuntime(907): Process: com.amaps.androidmap, PID: 907
12-12 06:19:45.500: E/AndroidRuntime(907): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amaps.androidmap/com.amaps.androidmap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.os.Handler.dispatchMessage(Handler.java:102)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.os.Looper.loop(Looper.java:137)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-12 06:19:45.500: E/AndroidRuntime(907): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 06:19:45.500: E/AndroidRuntime(907): at java.lang.reflect.Method.invoke(Method.java:515)
12-12 06:19:45.500: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-12 06:19:45.500: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-12 06:19:45.500: E/AndroidRuntime(907): at dalvik.system.NativeStart.main(Native Method)
12-12 06:19:45.500: E/AndroidRuntime(907): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-12 06:19:45.500: E/AndroidRuntime(907): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-12 06:19:45.500: E/AndroidRuntime(907): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Activity.setContentView(Activity.java:1928)
12-12 06:19:45.500: E/AndroidRuntime(907): at com.amaps.androidmap.MainActivity.onCreate(MainActivity.java:12)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Activity.performCreate(Activity.java:5243)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-12 06:19:45.500: E/AndroidRuntime(907): ... 11 more
12-12 06:19:45.500: E/AndroidRuntime(907): 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
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Fragment.instantiate(Fragment.java:597)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Fragment.instantiate(Fragment.java:561)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Activity.onCreateView(Activity.java:4777)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
12-12 06:19:45.500: E/AndroidRuntime(907): ... 20 more
12-12 06:19:45.500: E/AndroidRuntime(907): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.amaps.androidmap-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amaps.androidmap-2, /system/lib]]
12-12 06:19:45.500: E/AndroidRuntime(907): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-12 06:19:45.500: E/AndroidRuntime(907): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-12 06:19:45.500: E/AndroidRuntime(907): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-12 06:19:45.500: E/AndroidRuntime(907): at android.app.Fragment.instantiate(Fragment.java:583)
12-12 06:19:45.500: E/AndroidRuntime(907): ... 23 more
12-12 06:23:20.842: I/Process(907): Sending signal. PID: 907 SIG: 9
12-12 06:44:02.832: D/AndroidRuntime(1054): Shutting down VM
12-12 06:44:02.832: W/dalvikvm(1054): threadid=1: thread exiting with uncaught exception (group=0xb4aeab90)
12-12 06:44:02.852: E/AndroidRuntime(1054): FATAL EXCEPTION: main
12-12 06:44:02.852: E/AndroidRuntime(1054): Process: com.amaps.androidmap, PID: 1054
12-12 06:44:02.852: E/AndroidRuntime(1054): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amaps.androidmap/com.amaps.androidmap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.os.Handler.dispatchMessage(Handler.java:102)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.os.Looper.loop(Looper.java:137)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-12 06:44:02.852: E/AndroidRuntime(1054): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 06:44:02.852: E/AndroidRuntime(1054): at java.lang.reflect.Method.invoke(Method.java:515)
12-12 06:44:02.852: E/AndroidRuntime(1054): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-12 06:44:02.852: E/AndroidRuntime(1054): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-12 06:44:02.852: E/AndroidRuntime(1054): at dalvik.system.NativeStart.main(Native Method)
12-12 06:44:02.852: E/AndroidRuntime(1054): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-12 06:44:02.852: E/AndroidRuntime(1054): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Activity.setContentView(Activity.java:1928)
12-12 06:44:02.852: E/AndroidRuntime(1054): at com.amaps.androidmap.MainActivity.onCreate(MainActivity.java:12)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Activity.performCreate(Activity.java:5243)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-12 06:44:02.852: E/AndroidRuntime(1054): ... 11 more
12-12 06:44:02.852: E/AndroidRuntime(1054): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Fragment.instantiate(Fragment.java:597)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Fragment.instantiate(Fragment.java:561)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Activity.onCreateView(Activity.java:4777)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
12-12 06:44:02.852: E/AndroidRuntime(1054): ... 21 more
12-12 06:44:02.852: E/AndroidRuntime(1054): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.amaps.androidmap-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.amaps.androidmap-1, /system/lib]]
12-12 06:44:02.852: E/AndroidRuntime(1054): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-12 06:44:02.852: E/AndroidRuntime(1054): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-12 06:44:02.852: E/AndroidRuntime(1054): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-12 06:44:02.852: E/AndroidRuntime(1054): at android.app.Fragment.instantiate(Fragment.java:583)
12-12 06:44:02.852: E/AndroidRuntime(1054): ... 24 more
12-12 06:49:03.212: I/Process(1054): Sending signal. PID: 1054 SIG: 9
12-12 06:58:53.742: D/AndroidRuntime(1100): Shutting down VM
12-12 06:58:53.742: W/dalvikvm(1100): threadid=1: thread exiting with uncaught exception (group=0xb4aeab90)
12-12 06:58:53.762: E/AndroidRuntime(1100): FATAL EXCEPTION: main
12-12 06:58:53.762: E/AndroidRuntime(1100): Process: com.amaps.androidmap, PID: 1100
12-12 06:58:53.762: E/AndroidRuntime(1100): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amaps.androidmap/com.amaps.androidmap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.os.Handler.dispatchMessage(Handler.java:102)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.os.Looper.loop(Looper.java:137)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-12 06:58:53.762: E/AndroidRuntime(1100): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 06:58:53.762: E/AndroidRuntime(1100): at java.lang.reflect.Method.invoke(Method.java:515)
12-12 06:58:53.762: E/AndroidRuntime(1100): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-12 06:58:53.762: E/AndroidRuntime(1100): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-12 06:58:53.762: E/AndroidRuntime(1100): at dalvik.system.NativeStart.main(Native Method)
12-12 06:58:53.762: E/AndroidRuntime(1100): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-12 06:58:53.762: E/AndroidRuntime(1100): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Activity.setContentView(Activity.java:1928)
12-12 06:58:53.762: E/AndroidRuntime(1100): at com.amaps.androidmap.MainActivity.onCreate(MainActivity.java:12)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Activity.performCreate(Activity.java:5243)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-12 06:58:53.762: E/AndroidRuntime(1100): ... 11 more
12-12 06:58:53.762: E/AndroidRuntime(1100): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Fragment.instantiate(Fragment.java:597)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Fragment.instantiate(Fragment.java:561)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Activity.onCreateView(Activity.java:4777)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
12-12 06:58:53.762: E/AndroidRuntime(1100): ... 21 more
12-12 06:58:53.762: E/AndroidRuntime(1100): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.amaps.androidmap-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amaps.androidmap-2, /system/lib]]
12-12 06:58:53.762: E/AndroidRuntime(1100): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-12 06:58:53.762: E/AndroidRuntime(1100): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-12 06:58:53.762: E/AndroidRuntime(1100): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-12 06:58:53.762: E/AndroidRuntime(1100): at android.app.Fragment.instantiate(Fragment.java:583)
12-12 06:58:53.762: E/AndroidRuntime(1100): ... 24 more
12-12 06:59:41.712: I/Process(1100): Sending signal. PID: 1100 SIG: 9
i import the library from path :
adt-bundle-linux-x86-20131030/sdk/extras/google/google_play_services/libproject//google-play-services_lib/
i also made the reference but still nothing happen.Dont knw what to do.
I suspect that you have not referenced to the google play services library project properly. Make sure you do that first.
<uses-sdk
android:minSdkVersion="8"
Your min sdk is 8. Use SupportMapFragment and extend FragmentActivity and use support library.
or change to api level to 12 and above.
You are also missing
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
in Application Tag of manifest
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
Make sure you have referenced google play services library project properly and followed all the steps in the above link
Replace it:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/btnSurrey" />
with this:
<?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"/>
add this in maifest:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Your MapFragment should be defined like this.
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Add this in AndroidManifest.xml
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
In my app there are no compilation errors when i tried to run my app on android device it shows App stopped unexpectedly error .i didn't find the exact problem in lohcat here i am pasting the logcat details any one please exaplain this.
12-12 00:39:20.240: I/dalvikvm(687): Could not find method com.google.inject.Injector.getInstance, referenced from method de.dan_nrw.android.scroid.DependencyInjector.getInstance
12-12 00:39:20.310: W/dalvikvm(687): VFY: unable to resolve interface method 3344: Lcom/google/inject/Injector;.getInstance (Ljava/lang/Class;)Ljava/lang/Object;
12-12 00:39:20.310: D/dalvikvm(687): VFY: replacing opcode 0x72 at 0x000e
12-12 00:39:20.320: E/dalvikvm(687): Could not find class 'com.google.inject.Module[]', referenced from method de.dan_nrw.android.scroid.DependencyInjector.init
12-12 00:39:20.370: W/dalvikvm(687): VFY: unable to resolve new-array 684 ([Lcom/google/inject/Module;) in Lde/dan_nrw/android/scroid/DependencyInjector;
12-12 00:39:20.370: D/dalvikvm(687): VFY: replacing opcode 0x23 at 0x0001
12-12 00:39:20.413: W/dalvikvm(687): Unable to resolve superclass of Lde/dan_nrw/android/scroid/ProductiveModule; (472)
12-12 00:39:20.450: W/dalvikvm(687): Link of class 'Lde/dan_nrw/android/scroid/ProductiveModule;' failed
12-12 00:39:20.450: D/dalvikvm(687): DexOpt: unable to opt direct call 0x0d30 at 0x06 in Lde/dan_nrw/android/scroid/DependencyInjector;.init
12-12 00:39:20.471: D/AndroidRuntime(687): Shutting down VM
12-12 00:39:20.471: W/dalvikvm(687): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-12 00:39:20.511: E/AndroidRuntime(687): FATAL EXCEPTION: main
12-12 00:39:20.511: E/AndroidRuntime(687): java.lang.NoClassDefFoundError: com.google.inject.Module[]
12-12 00:39:20.511: E/AndroidRuntime(687): at de.dan_nrw.android.scroid.DependencyInjector.init(DependencyInjector.java:37)
12-12 00:39:20.511: E/AndroidRuntime(687): at de.dan_nrw.android.scroid.ScroidWallpaperGallery.<init>(ScroidWallpaperGallery.java:84)
12-12 00:39:20.511: E/AndroidRuntime(687): at java.lang.Class.newInstanceImpl(Native Method)
12-12 00:39:20.511: E/AndroidRuntime(687): at java.lang.Class.newInstance(Class.java:1319)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.os.Looper.loop(Looper.java:137)
12-12 00:39:20.511: E/AndroidRuntime(687): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-12 00:39:20.511: E/AndroidRuntime(687): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 00:39:20.511: E/AndroidRuntime(687): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 00:39:20.511: E/AndroidRuntime(687): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-12 00:39:20.511: E/AndroidRuntime(687): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-12 00:39:20.511: E/AndroidRuntime(687): at dalvik.system.NativeStart.main(Native Method)
12-12 00:39:23.931: I/Process(687): Sending signal. PID: 687 SIG: 9
12-12 00:44:23.441: I/dalvikvm(728): Could not find method com.google.inject.Injector.getInstance, referenced from method de.dan_nrw.android.scroid.DependencyInjector.getInstance
12-12 00:44:23.491: W/dalvikvm(728): VFY: unable to resolve interface method 3344: Lcom/google/inject/Injector;.getInstance (Ljava/lang/Class;)Ljava/lang/Object;
12-12 00:44:23.491: D/dalvikvm(728): VFY: replacing opcode 0x72 at 0x000e
12-12 00:44:23.491: E/dalvikvm(728): Could not find class 'com.google.inject.Module[]', referenced from method de.dan_nrw.android.scroid.DependencyInjector.init
12-12 00:44:23.491: W/dalvikvm(728): VFY: unable to resolve new-array 684 ([Lcom/google/inject/Module;) in Lde/dan_nrw/android/scroid/DependencyInjector;
12-12 00:44:23.491: D/dalvikvm(728): VFY: replacing opcode 0x23 at 0x0001
12-12 00:44:23.511: W/dalvikvm(728): Unable to resolve superclass of Lde/dan_nrw/android/scroid/ProductiveModule; (472)
12-12 00:44:23.521: W/dalvikvm(728): Link of class 'Lde/dan_nrw/android/scroid/ProductiveModule;' failed
12-12 00:44:23.551: D/dalvikvm(728): DexOpt: unable to opt direct call 0x0d30 at 0x06 in Lde/dan_nrw/android/scroid/DependencyInjector;.init
12-12 00:44:23.551: D/AndroidRuntime(728): Shutting down VM
12-12 00:44:23.561: W/dalvikvm(728): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-12 00:44:23.641: E/AndroidRuntime(728): FATAL EXCEPTION: main
12-12 00:44:23.641: E/AndroidRuntime(728): java.lang.NoClassDefFoundError: com.google.inject.Module[]
12-12 00:44:23.641: E/AndroidRuntime(728): at de.dan_nrw.android.scroid.DependencyInjector.init(DependencyInjector.java:37)
12-12 00:44:23.641: E/AndroidRuntime(728): at de.dan_nrw.android.scroid.ScroidWallpaperGallery.<init>(ScroidWallpaperGallery.java:84)
12-12 00:44:23.641: E/AndroidRuntime(728): at java.lang.Class.newInstanceImpl(Native Method)
12-12 00:44:23.641: E/AndroidRuntime(728): at java.lang.Class.newInstance(Class.java:1319)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.os.Looper.loop(Looper.java:137)
12-12 00:44:23.641: E/AndroidRuntime(728): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-12 00:44:23.641: E/AndroidRuntime(728): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 00:44:23.641: E/AndroidRuntime(728): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 00:44:23.641: E/AndroidRuntime(728): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-12 00:44:23.641: E/AndroidRuntime(728): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-12 00:44:23.641: E/AndroidRuntime(728): at dalvik.system.NativeStart.main(Native Method)
It could be you forgot to add a necessary jar to the build path
Here is my code to display the google map in my android emulator using google AVD....
How to fix this problem?anybody can know this?
Map.java:
public class MapsActivity extends MapActivity
{
private MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
Xml File:
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0l4sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ"
>
</com.google.android.maps.MapView>
Manifost File:
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-library android:name="com.google.android.maps" />
Output:
In my emulator map activity has stopped unexpexctly..
i got the runtime exception
01-04 10:36:24.540: D/dalvikvm(641): Not late-enabling CheckJNI (already on)
01-04 10:36:25.290: W/dalvikvm(641): Unable to resolve superclass of Lcom/example/MapsActivity; (10)
01-04 10:36:25.290: W/dalvikvm(641): Link of class 'Lcom/example/MapsActivity;' failed
01-04 10:36:25.290: D/AndroidRuntime(641): Shutting down VM
01-04 10:36:25.290: W/dalvikvm(641): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-04 10:36:25.430: E/AndroidRuntime(641): FATAL EXCEPTION: main
01-04 10:36:25.430: E/AndroidRuntime(641): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MapsActivity}: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.os.Looper.loop(Looper.java:137)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-04 10:36:25.430: E/AndroidRuntime(641): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 10:36:25.430: E/AndroidRuntime(641): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 10:36:25.430: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-04 10:36:25.430: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-04 10:36:25.430: E/AndroidRuntime(641): at dalvik.system.NativeStart.main(Native Method)
01-04 10:36:25.430: E/AndroidRuntime(641): Caused by: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:36:25.430: E/AndroidRuntime(641): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-04 10:36:25.430: E/AndroidRuntime(641): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-04 10:36:25.430: E/AndroidRuntime(641): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-04 10:36:25.430: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
01-04 10:36:25.430: E/AndroidRuntime(641): ... 11 more
01-04 10:36:31.140: W/dalvikvm(679): Unable to resolve superclass of Lcom/example/MapsActivity; (10)
01-04 10:36:31.160: W/dalvikvm(679): Link of class 'Lcom/example/MapsActivity;' failed
01-04 10:36:31.160: D/AndroidRuntime(679): Shutting down VM
01-04 10:36:31.180: W/dalvikvm(679): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-04 10:36:31.240: E/AndroidRuntime(679): FATAL EXCEPTION: main
01-04 10:36:31.240: E/AndroidRuntime(679): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MapsActivity}: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.os.Looper.loop(Looper.java:137)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-04 10:36:31.240: E/AndroidRuntime(679): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 10:36:31.240: E/AndroidRuntime(679): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 10:36:31.240: E/AndroidRuntime(679): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-04 10:36:31.240: E/AndroidRuntime(679): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-04 10:36:31.240: E/AndroidRuntime(679): at dalvik.system.NativeStart.main(Native Method)
01-04 10:36:31.240: E/AndroidRuntime(679): Caused by: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:36:31.240: E/AndroidRuntime(679): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-04 10:36:31.240: E/AndroidRuntime(679): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-04 10:36:31.240: E/AndroidRuntime(679): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-04 10:36:31.240: E/AndroidRuntime(679): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
01-04 10:36:31.240: E/AndroidRuntime(679): ... 11 more
01-04 10:37:23.619: W/dalvikvm(720): Unable to resolve superclass of Lcom/example/MapsActivity; (10)
01-04 10:37:23.659: W/dalvikvm(720): Link of class 'Lcom/example/MapsActivity;' failed
01-04 10:37:23.659: D/AndroidRuntime(720): Shutting down VM
01-04 10:37:23.669: W/dalvikvm(720): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-04 10:37:23.699: E/AndroidRuntime(720): FATAL EXCEPTION: main
01-04 10:37:23.699: E/AndroidRuntime(720): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example/com.example.MapsActivity}: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.os.Looper.loop(Looper.java:137)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-04 10:37:23.699: E/AndroidRuntime(720): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 10:37:23.699: E/AndroidRuntime(720): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 10:37:23.699: E/AndroidRuntime(720): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-04 10:37:23.699: E/AndroidRuntime(720): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-04 10:37:23.699: E/AndroidRuntime(720): at dalvik.system.NativeStart.main(Native Method)
01-04 10:37:23.699: E/AndroidRuntime(720): Caused by: java.lang.ClassNotFoundException: com.example.MapsActivity
01-04 10:37:23.699: E/AndroidRuntime(720): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-04 10:37:23.699: E/AndroidRuntime(720): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-04 10:37:23.699: E/AndroidRuntime(720): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-04 10:37:23.699: E/AndroidRuntime(720): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
01-04 10:37:23.699: E/AndroidRuntime(720): ... 11 more
Output screen:
google map view screen shot
I think problem with your API key only. Any how check the link below you will get an idea.
Displaying Google maps in Android Emulator
I found one thing in your manifest, you written
<uses-library android:name="com.google.android.maps" />
after </application> i think it may wrong
In manifest file write as below and try once
<application
<uses-library android:name="com.google.android.maps" />
New Answer
Please check this link, it may help you.
Enable internet for Android Emulator
Your mentioned code is right But i have two doubt is that
1. Google MAP API
Ans .To get Google MAP API Here
2. Check Emulator's Internet.
Ans . Open CMD
D:\SOFTWARE\Android-SDK\android-sdk-2.2>emulator -avd avdname -dns-server 8.8.8.8
add google maps library in your manifest and it should work
Move :
<uses-library android:name="com.google.android.maps" />
within the application tag. You have written outside the application tag in manifest file.
For your second problem:
I am sure you have copied the map key from some where else. This is causing only blank screen on emulator. Try to generate your own Map Key following:
http://code.google.com/android/add-ons/google-apis/mapkey.html
the error class not found exception is when actitvity is not declared in manifest
if you have declared it and then also error comes please please check you may have
included a jar file twice in your project
What's the reason for this error? I only get the error at certain times when I press the textview.
12 12:30:24.301: ERROR/AndroidRuntime(380): java.lang.NullPointerException
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at gps.app.tkartor.Tkartor.onClick(Tkartor.java:195)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.view.View.performClick(View.java:2408)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.view.View$PerformClick.run(View.java:8816)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.os.Handler.handleCallback(Handler.java:587)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.os.Handler.dispatchMessage(Handler.java:92)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.os.Looper.loop(Looper.java:123)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at java.lang.reflect.Method.invoke(Method.java:521)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-12 12:30:24.301: ERROR/AndroidRuntime(380): at dalvik.system.NativeStart.main(Native Method)
<TextView android:id="#+id/tvReload" style="#style/ButtonText"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="PRESS TO RELOAD"
android:textStyle="bold" android:layout_alignParentBottom="true"
android:textSize="12sp" android:clickable="true" />
java.lang.NullPointerException
Occurs when your object is null or not initiallized & you are trying to access it.
Crosscheck whether all your objects are properly initialized.
Specially in your code Check line number 195 of Tkartor.java file, there you have atleast one object null.