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
Related
I know this question has been asked many times here, but none of the solutions provided stopped my app from crashing.
Here is my code from the MainActivity:
package com.example.gpstracking2;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Marker;
public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
Marker marker = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Here is the code from the activity_main.xml from the layout folder:
<?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" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Here is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpstracking2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.gpstracking2.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gpstracking2.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<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.example.gpstracking2.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="KEY"/>
</application>
</manifest>
And here is the logcat:
10-06 16:57:27.966: W/dalvikvm(6735): VFY: unable to resolve static field 1346 (MapAttrs) in Lcom/google/android/gms/R$styleable;
10-06 16:57:27.966: D/dalvikvm(6735): VFY: replacing opcode 0x62 at 0x000e
10-06 16:57:27.966: D/AndroidRuntime(6735): Shutting down VM
10-06 16:57:27.966: W/dalvikvm(6735): threadid=1: thread exiting with uncaught exception (group=0x41df3700)
10-06 16:57:27.966: E/AndroidRuntime(6735): FATAL EXCEPTION: main
10-06 16:57:27.966: E/AndroidRuntime(6735): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:284)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Activity.setContentView(Activity.java:1895)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.example.gpstracking2.MainActivity.onCreate(MainActivity.java:25)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Activity.performCreate(Activity.java:5133)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.os.Looper.loop(Looper.java:137)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-06 16:57:27.966: E/AndroidRuntime(6735): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 16:57:27.966: E/AndroidRuntime(6735): at java.lang.reflect.Method.invoke(Method.java:525)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-06 16:57:27.966: E/AndroidRuntime(6735): at dalvik.system.NativeStart.main(Native Method)
10-06 16:57:27.976: W/ActivityManager(428): Force finishing activity com.example.gpstracking2/.MainActivity
10-06 16:57:28.056: D/dalvikvm(428): GC_FOR_ALLOC freed 2309K, 20% free 17147K/21256K, paused 68ms, total 68ms
10-06 16:57:28.566: W/ActivityManager(428): Activity pause timeout for ActivityRecord{42889d90 u0 com.example.gpstracking2/.MainActivity}
10-06 16:57:28.616: I/ActivityManager(428): No longer want com.android.defcontainer (pid 5432): empty #17
10-06 16:57:29.876: I/Process(6735): Sending signal. PID: 6735 SIG: 9
10-06 16:57:29.876: I/ActivityManager(428): Process com.example.gpstracking2 (pid 6735) has died.
10-06 16:57:29.896: W/InputMethodManagerService(428): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4266be70 attribute=null, token = android.os.BinderProxy#425f0da8
library is not added properly..
check project -> right click on properties -.java build path -order and exprot select googleplayservices library.
My code is working in way of edited as like as below and importing google library,
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
Hi I am trying to run an android app. Where my goal was to display a radar graph based on user preferences for that I have used the webview and sending the username to php file.
But Now I was getting an error stating that "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity"
I Have tried my level best to solve this but I could able to it. and in error it was stated the communication class was not mentioned So I have also mentioned but I required the radar part to display. So Please help me in solving this.
Here is my logcat
08-04 19:59:21.861: D/gralloc_goldfish(654): Emulator without GPU emulation detected.
08-04 19:59:22.071: W/TextLayoutCache(654): computeValuesWithHarfbuzz -- need to force to single run
08-04 19:59:32.541: D/dalvikvm(654): GC_CONCURRENT freed 177K, 3% free 14296K/14599K, paused 7ms+7ms
08-04 19:59:36.962: W/TextLayoutCache(654): computeValuesWithHarfbuzz -- need to force to single run
08-04 19:59:45.762: W/SingleClientConnManager(654): Invalid use of SingleClientConnManager: connection still allocated.
08-04 19:59:45.762: W/SingleClientConnManager(654): Make sure to release the connection before allocating another one.
08-04 19:59:45.811: I/System.out(654): Response : User Found
08-04 19:59:45.811: I/System.out(654): ---IF---
08-04 19:59:46.682: D/dalvikvm(654): GC_CONCURRENT freed 214K, 3% free 14607K/14919K, paused 6ms+8ms
08-04 19:59:46.831: D/dalvikvm(654): GC_FOR_ALLOC freed 13K, 2% free 14946K/15239K, paused 52ms
08-04 19:59:50.781: D/AndroidRuntime(654): Shutting down VM
08-04 19:59:50.781: W/dalvikvm(654): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-04 19:59:50.831: E/AndroidRuntime(654): FATAL EXCEPTION: main
08-04 19:59:50.831: E/AndroidRuntime(654): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.os.Looper.loop(Looper.java:137)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-04 19:59:50.831: E/AndroidRuntime(654): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 19:59:50.831: E/AndroidRuntime(654): at java.lang.reflect.Method.invoke(Method.java:511)
08-04 19:59:50.831: E/AndroidRuntime(654): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-04 19:59:50.831: E/AndroidRuntime(654): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-04 19:59:50.831: E/AndroidRuntime(654): at dalvik.system.NativeStart.main(Native Method)
08-04 19:59:50.831: E/AndroidRuntime(654): Caused by: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-04 19:59:50.831: E/AndroidRuntime(654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-04 19:59:50.831: E/AndroidRuntime(654): ... 11 more
08-04 20:06:29.651: D/gralloc_goldfish(707): Emulator without GPU emulation detected.
08-04 20:06:29.802: W/TextLayoutCache(707): computeValuesWithHarfbuzz -- need to force to single run
08-04 20:06:35.271: D/dalvikvm(707): GC_CONCURRENT freed 133K, 2% free 14335K/14599K, paused 7ms+6ms
08-04 20:06:47.093: W/TextLayoutCache(707): computeValuesWithHarfbuzz -- need to force to single run
08-04 20:06:55.241: W/SingleClientConnManager(707): Invalid use of SingleClientConnManager: connection still allocated.
08-04 20:06:55.241: W/SingleClientConnManager(707): Make sure to release the connection before allocating another one.
08-04 20:06:55.352: D/dalvikvm(707): GC_CONCURRENT freed 298K, 3% free 14484K/14855K, paused 6ms+8ms
08-04 20:06:55.441: I/System.out(707): Response : User Found
08-04 20:06:55.512: I/System.out(707): ---IF---
08-04 20:06:56.211: D/dalvikvm(707): GC_FOR_ALLOC freed 70K, 3% free 14754K/15111K, paused 46ms
08-04 20:06:56.334: D/dalvikvm(707): GC_FOR_ALLOC freed 3K, 3% free 15023K/15367K, paused 50ms
08-04 20:07:00.851: D/AndroidRuntime(707): Shutting down VM
08-04 20:07:00.851: W/dalvikvm(707): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-04 20:07:00.901: E/AndroidRuntime(707): FATAL EXCEPTION: main
08-04 20:07:00.901: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.newairways/com.example.newairways.communication}: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:137)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-04 20:07:00.901: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 20:07:00.901: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:511)
08-04 20:07:00.901: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-04 20:07:00.901: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-04 20:07:00.901: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
08-04 20:07:00.901: E/AndroidRuntime(707): Caused by: java.lang.ClassCastException: com.example.newairways.communication cannot be cast to android.app.Activity
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-04 20:07:00.901: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-04 20:07:00.901: E/AndroidRuntime(707): ... 11 more
Here is my manifesto file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newairways"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.newairways.login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.newairways.menu"
android:label="#string/app_name" >
</activity>s
<activity
android:name="com.example.newairways.bar"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.radar"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.measure"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.plan"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.day0"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.goaltest"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.relationship"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.start"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.discipline"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.skills"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.knowledge"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.emotions"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.adaptation"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.leadership"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.lifequality"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.Globalvars"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.newairways.communication"
android:label="#string/app_name" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Does your activity extend android.app.activity ? Is the activity mentioned in the manifest file. Is the base package and fully qualified name of the activity class correct??
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.
I am new in Google Map and so many things aren't clear enough to me for that reason.So i expect some expert's direction on this regard.I read This Guide and did everything what it says.I use google map api v2 and get a map key.Then i make a sample project following that link and select target version android 2.2(while running the project).But a list of error occurs after running then example in eclipse android emulator.My logcat view shows:
01-31 00:51:59.226: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-31 00:51:59.236: E/AndroidRuntime(329): FATAL EXCEPTION: main
01-31 00:51:59.236: E/AndroidRuntime(329): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googleMapApp/com.googleMapApp.LocationProfileManagerActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 00:51:59.236: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
01-31 00:51:59.236: E/AndroidRuntime(329): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.Activity.setContentView(Activity.java:1647)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.googleMapApp.LocationProfileManagerActivity.onCreate(LocationProfileManagerActivity.java:14)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 00:51:59.236: E/AndroidRuntime(329): ... 11 more
01-31 00:51:59.236: E/AndroidRuntime(329): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.googleMapApp-1.apk]
01-31 00:51:59.236: E/AndroidRuntime(329): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-31 00:51:59.236: E/AndroidRuntime(329): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
01-31 00:51:59.236: E/AndroidRuntime(329): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-31 00:51:59.236: E/AndroidRuntime(329): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
My Manifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googleMapApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.googleMapApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.googleMapApp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Require OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LocationProfileManagerActivity"
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="myMapKey"/>
</application>
</manifest>
My main.xml is:
<?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"
class="com.google.android.gms.maps.MapFragment"/>
My activity.java is:
package com.googleMapApp;
import android.app.Activity;
import android.os.Bundle;
public class LocationProfileManagerActivity extends Activity {
/** Called when the activity is first created. */
//private GoogleMap map;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Sorry for this lengthy description,but i want to show you exactly what i did.I think as a newcomer i did a lot of mistake on this way.so i expect someone will guide me that.
You are using features only available in later APIs, namely Fragment. If you want to compile to support 2.2, you need to include the Support Library in your project. You will also have to make the following changes to use support fragments instead of regular fragments --
In main.xml, change
class="com.google.android.gms.maps.MapFragment"/>
to
class="com.google.android.gms.maps.SupportMapFragment"/>
and in your activity.java, change
public class LocationProfileManagerActivity extends Activity {
to
public class LocationProfileManagerActivity extends FragmentActivity {
you need to make two changes
Since as you are sdk version is below 12, need to make following change
1)
main.xml
Replace
class="com.google.android.gms.maps.MapFragment"/>
with
class="com.google.android.gms.maps.SupportMapFragment"/>
2) activity.java
Need to extend FragmentActivity instead of Activity
If you want to test in emulator , then download the google_play_services_apk and install it in emulator.
Maps API v2 cannot be run in an emulator because of its dependency on Google Play Services, which is bundled in the Google Play Store .apk. It can be hacked together though, you can read about it here on the first Google result for "Google maps v2 emulator". Also you can still use V1 for a limited time, you can get started here.
I've been trying to get started with Android programming for a while now. I'm mainly a .NET developer with no Java experience for 8 years (university).
I can compile and run samples no problem but the moment I try and rename my package/class it fails. I believe I've updated the manifest and triple checked it (Copied and pasted name, selected it with Eclipse) yet it always fails with a java.lang.ClassNotFoundException:
12-02 09:12:21.088: ERROR/AndroidRuntime(233): Uncaught handler: thread main exiting due to uncaught exception
12-02 09:12:21.178: ERROR/AndroidRuntime(233): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.anddev.cheesemp.helloandworld/org.anddev.cheesemp.helloandworld.HelloAndEngine}: java.lang.ClassNotFoundException: org.anddev.cheesemp.helloandworld.HelloAndEngine in loader dalvik.system.PathClassLoader#43d0c0d0
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.os.Handler.dispatchMessage(Handler.java:99)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.os.Looper.loop(Looper.java:123)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at java.lang.reflect.Method.invokeNative(Native Method)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at java.lang.reflect.Method.invoke(Method.java:521)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at dalvik.system.NativeStart.main(Native Method)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): Caused by: java.lang.ClassNotFoundException: org.anddev.cheesemp.helloandworld.HelloAndEngine in loader dalvik.system.PathClassLoader#43d0c0d0
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
12-02 09:12:21.178: ERROR/AndroidRuntime(233): ... 11 more
Manifest is here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="org.anddev.cheesemp.helloandworld">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name="org.anddev.cheesemp.helloandworld.HelloAndEngine">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" \>
</manifest>
Class definition is here:
package org.anddev.cheesemp.helloandworld;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.HorizontalAlign;
import android.graphics.Color;
import android.graphics.Typeface;
/**
* #author Nicolas Gramlich
* #since 11:54:51 - 03.04.2010
*/
public class HelloAndEngine extends BaseGameActivity
This sample is from AndEngine but I've had the same issue with every sample I modify. I can't help but feel I've missed something and nothing I found searching has helped.
Any advice appreciated!
Try this.
<activity android:label="#string/app_name" android:name=".HelloAndEngine">
You don't need the fully qualified class name. Also, if you are working with Eclipse and rename a package go to Project → Clean and let it clean up your project, fixing up references and so on if anything is broken.
This is a bug in eclipse android tools
http://code.google.com/p/android/issues/detail?id=2824
To Fix -> Right click on the project go to Android tools -> Rename application package..
And also check AndroidManifest.xml if it updated correctly, in my case it didn't, that should solve this problem