RicardoR Posted July 10, 2013 at 09:02 PM Report #518162 Posted July 10, 2013 at 09:02 PM Boas pessoal. Construi uma aplicação simples com a API da google. O programa compila sem problema, insta-la no telemovel, so que ao iniciar crasha de imediato. O programa é o seguinte: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidmapsv2" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" android:protectionLevel="signature"></permission> <uses-permission android:name="com.example.androidmapsv2.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"/> <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" > <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="CHAVE"/> <activity android:name="com.example.androidmapsv2.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> MainActivity.java: package com.example.androidmapsv2; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } activity_main.xml <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" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment"/> </RelativeLayout> Nao sei se importa, mas estou a usar o eclipse e importei a biblioteca do GooglePlay e adicionei ao projeto Muito obrigado, abraço 😉
Knitter Posted July 10, 2013 at 09:24 PM Report #518168 Posted July 10, 2013 at 09:24 PM Corre o logcat e vê qual é a excepção que tens no terminal, ficas logo a saber porque é que rebentou ao executar.
RicardoR Posted July 10, 2013 at 11:27 PM Author Report #518205 Posted July 10, 2013 at 11:27 PM (edited) Obrigado pela resposta. O erro que me estava a dar é 07-11 00:38:22.214: E/AndroidRuntime(16391): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread.access$600(ActivityThread.java:140) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.os.Handler.dispatchMessage(Handler.java:99) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.os.Looper.loop(Looper.java:137) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread.main(ActivityThread.java:4898) 07-11 00:38:22.214: E/AndroidRuntime(16391): at java.lang.reflect.Method.invokeNative(Native Method) 07-11 00:38:22.214: E/AndroidRuntime(16391): at java.lang.reflect.Method.invoke(Method.java:511) 07-11 00:38:22.214: E/AndroidRuntime(16391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 07-11 00:38:22.214: E/AndroidRuntime(16391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 07-11 00:38:22.214: E/AndroidRuntime(16391): at dalvik.system.NativeStart.main(Native Method) 07-11 00:38:22.214: E/AndroidRuntime(16391): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 07-11 00:38:22.214: E/AndroidRuntime(16391): at com.android.internal.policy.impl.Phonewindow.setContentView(Phonewindow.java:308) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Activity.setContentView(Activity.java:1924) 07-11 00:38:22.214: E/AndroidRuntime(16391): at com.example.androidmapsv2.MainActivity.onCreate(MainActivity.java:11) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Activity.performCreate(Activity.java:5206) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 07-11 00:38:22.214: E/AndroidRuntime(16391): ... 11 more 07-11 00:38:22.214: E/AndroidRuntime(16391): 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 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Fragment.instantiate(Fragment.java:584) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Fragment.instantiate(Fragment.java:552) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Activity.onCreateView(Activity.java:4849) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 07-11 00:38:22.214: E/AndroidRuntime(16391): ... 21 more 07-11 00:38:22.214: E/AndroidRuntime(16391): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment 07-11 00:38:22.214: E/AndroidRuntime(16391): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 07-11 00:38:22.214: E/AndroidRuntime(16391): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 07-11 00:38:22.214: E/AndroidRuntime(16391): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 07-11 00:38:22.214: E/AndroidRuntime(16391): at android.app.Fragment.instantiate(Fragment.java:574) 07-11 00:38:22.214: E/AndroidRuntime(16391): ... 24 more Sabes o que é? Abraço 😉 Edited July 10, 2013 at 11:42 PM by RicardoR
KTachyon Posted July 10, 2013 at 11:46 PM Report #518206 Posted July 10, 2013 at 11:46 PM (edited) Tens que utilizar o SupportMapFragment em vez do MapFragment, uma vez que estás a suportar versões anteriores à 12: http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html Use this class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment. No teu AndroidManifest: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> Edited July 10, 2013 at 11:47 PM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
RicardoR Posted July 10, 2013 at 11:53 PM Author Report #518209 Posted July 10, 2013 at 11:53 PM Continua a não funcionar, mudei o minSdkVersion para 12 e faz a mesma coisa... :/ Abraço
KTachyon Posted July 11, 2013 at 01:02 AM Report #518214 Posted July 11, 2013 at 01:02 AM (edited) Basicamente: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment Isto diz-te que essa classe não existe, o que acredito que se aconteceu também com o SupportMapFragment, significa que a biblioteca que importaste para o projecto ou não tem essa classe, ou não está no build path por alguma razão. Seguiste as instruções? http://developer.android.com/google/play-services/setup.html EDIT: Mais concretamente, o passo 4 da instalação, seguido do "Set Up a Project with the Library". Edited July 11, 2013 at 01:03 AM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
Ernest Posted July 11, 2013 at 04:09 AM Report #518219 Posted July 11, 2013 at 04:09 AM (edited) Bom dia, Citação de RicardoR : Não sei se importa, mas estou a usar o eclipse e importei a biblioteca do GooglePlay e adicionei ao projeto Importa sim ! já que para mim existe uma forte probabilidade que seja ai mesmo o problema no caso o você fez o resto corretamente. Não sei muito bem o que chama de biblioteca do GooglePlay , há um monte de Google Play .... Google Play Services, Google Play APK Expansion Library , o Google Play Billing Library, etc... OK, fala de Google Play Services , provavelmente ... mas quanto mais for claro melhore. Etapas Instalar corretamente : 1- JDK 1.7_25 2- Eclipse 4.3 KEPLER 3- Google Plugin for Eclipse 4- Android SDK API (aconselhável API Level entre 15 e 17 ) 5- dizer a Eclipse onde está o SDK Android Google Maps Android API v2 : I- Abra o Android SDK Manager e instale Extras → Google Play services II- clique direito no nome do projecto Android -> properties -> Android meter o Project build target = Google APIs III- Importar a biblioteca Google Play services que foi baixada (na etapa I) no Eclipse via : File → Import → Android → Existing Android Code into Workspace IV- Para usar esta biblioteca definir uma dependência de biblioteca no seu projecto Android : Android Dependencies No meu caso o caminho google-play-services_lib.jar : C:\android-sdk_r21.1-windows\extras\google\google_play_services\libproject\google-play-services_lib\bin\google-play-services_lib.jar V- Obter a CHAVE Google Map : Google Maps API key : https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api Meter a Google Maps API key (CHAVE) no AndroidManifest.xml Cordialmente Ernest Duarte Edited July 11, 2013 at 04:14 AM by Ernest Duarte
KTachyon Posted July 11, 2013 at 09:27 AM Report #518254 Posted July 11, 2013 at 09:27 AM Só um extra: segundo as instruções, deve-se fazer uma cópia do projecto da pasta extras para outro local e importar o projecto desse novo local. Isto faz sentido por uma razão: Estás a desenvolver uma aplicação que tem a dependência dessa biblioteca, que corresponde ao projecto tal como está na pasta "extras". Quando houver uma actualização, esse projecto vai mudar, podendo passar a criar conflitos com a aplicação que estás a desenvolver. Se copiares a pasta para outro local e a importares daí para o projecto, não tens esse problema. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
Ernest Posted July 11, 2013 at 03:24 PM Report #518341 Posted July 11, 2013 at 03:24 PM (edited) Bom dia, Os pontos delicados são os pontos III- e IV- No meu caso fiz : clique direito no nome do projecto Android -> properties -> Android em baixo no Library tem um controlo Add... e meti-lhe o caminho até C:\android-sdk_r21.1-windows\extras\google\google_play_services\libproject\google-play-services_lib Outro ponto Google Maps só funciona no Device. No Device Nexus S / Android 4.1.2, instalei a aplicação Google Play Services version 3.1.36 ou mais recente a partir de Google Play Store Utilizo-a para aceder aos serviços Google Cloud Platform : Google Maps, Google AppEngine, Google Drive, Google Compute Engine , Google Cloud Messaging (GCM) etc.... Estou a realizar um projecto para uma empresa, com Android ligado au Cloud Computing que utiliza todos esses serviços depois de ter estudado as soluções de Amazon WS EC2, S3 , Windows Azure Mobile Services, http://buddy.com/ (muito bom também mas não se pode tocar na "black box" deles é promovido por o dueto MS/NOKIA) finalmente resolvi utilizar o Google Cloud Platform. Cordialmente Ernest Duarte Edited July 11, 2013 at 03:27 PM by Ernest Duarte
RicardoR Posted July 11, 2013 at 07:41 PM Author Report #518406 Posted July 11, 2013 at 07:41 PM Obrigado pela resposta. Tinha o Eclipse Juno mas de resto penso já ter feito tudo o que foi dito. Vou refazer e passar a copiar a pasta extras para o projeto para evitar alteração de ficheiros.. Não sei se pode estar relacionado, mas há tempos tive que voltar à versao 1.6 da versão do java quando estava a trabalhar noutro projeto. Pode ser disso? Obrigado pela atenção 😉
Ernest Posted July 11, 2013 at 09:08 PM Report #518423 Posted July 11, 2013 at 09:08 PM Bom dia, Utilizo o Java Platform JDK 1.7 update 25 por questões de bugs e de segurança nas versões anteriores que foram corregidas pela ORACLE nesta nova versão. Mas não esta relacionado com Android. Utilizo o Eclipse Kepler por que Juno não resolve as dependências corretamente entre projetos o que faz que se deve fazer um clean e em seguida um build para ele refazer as ligações como deve ser. Paralelamente ao projeto profissional estou a preparar um tutorial em português sobre Android conectado ao Google Cloud Platform : Google AppEngine, Cloud Endpoints, REST, Google Compute Engine, Modules, VM Runtimes, Google Drive, Google Apps, Google Cloud Messaging , ... Google AppEngine PaaS, vai ter muitas transformações ! Uma delas é funcionar sobre o Cloud IaaS Compute Engine em VM Runtimes e usar Modules. O tutorial deve estar pronto la para o fim deste mês, depois meto um link aqui no fórum. Cordialmente Ernest Duarte
RicardoR Posted July 11, 2013 at 11:47 PM Author Report #518447 Posted July 11, 2013 at 11:47 PM (edited) A aplicação já não crasha! Voltei a instalar tudo, incluindo todos os pacotes do SDK e já está a funcionar. Obrigadão pela ajuda pessoal Grande abraço 😉 Edited July 12, 2013 at 12:05 AM by RicardoR
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now