不幸的是,当尝试集成Google地图时,项目已停止

时间:2014-04-27 21:53:29

标签: android

我正在尝试将Google地图集成到我的应用中。收到一个API密钥,粘贴它,安装Google Play Services,apk文件,权限也行。试图编译。代码看起来与教程中的类似,所以作为清单。但我收到了#34;遗憾的是项目停止了#34;。 我尝试过很多教程 - 没有任何帮助。这是一个代码:

cont.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/cont_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Contacts"
        android:textSize="14dp" />

    <Button
        android:id="@+id/n_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="News"
        android:textSize="14dp" />

    <Button
        android:id="@+id/about_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="About"
        android:textSize="14dp" />

    <Button
        android:id="@+id/help_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/about_1"
        android:text="Help"
        android:textSize="14dp" />

    <Button
        android:id="@+id/info_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Info"
        android:textSize="14dp" />

    <Button
        android:id="@+id/don_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/about_1"
        android:text="Donate"
        android:textSize="14dp" />

    <Button
        android:id="@+id/zkt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="25dp"
        android:layout_toRightOf="@+id/help_1"
        android:text="Calculate"
        android:textSize="14dp" />

    <WebView
        android:id="@+id/web"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/about_1" />

    <fragment 
        android:id="@+id/fr"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        />

</RelativeLayout>

Cont.java

package com.example.sadaka;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class Cont extends FragmentActivity{
    SupportMapFragment fr;

    GoogleMap map;
@Override
public void onCreate(Bundle conts){
    Button zakat,cont,help,about,n,info,don;
    WebView web;

    super.onCreate(conts);
    setContentView(R.layout.cont);
    zakat=(Button)findViewById(R.id.zkt_1);
    cont=(Button)findViewById(R.id.cont_1);
    help=(Button)findViewById(R.id.help_1);
    about=(Button)findViewById(R.id.about_1);
    n=(Button)findViewById(R.id.n_1);
    info=(Button)findViewById(R.id.info_1);
    don=(Button)findViewById(R.id.don_1);
    web=(WebView)findViewById(R.id.web);
    //web.loadUrl("https://www.google.com/maps/@48.8374914,2.242815,4189m/data=!3m1!1e3");
    fr=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fr);
    map=fr.getMap();
    if(map==null){
        finish();
        return;
    }
    init();
    zakat.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Zakat.class);
            startActivity(i1);
        }
    });
    cont.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Cont.class);
            startActivity(i1);
        }
    });
    help.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Zakat.class);
            startActivity(i1);
        }
    });
    about.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Zakat.class);
            startActivity(i1);
        }
    });
    n.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,MainActivity.class);
            startActivity(i1);
        }
    });
    info.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Inf.class);
            startActivity(i1);
        }
    });
    don.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i1=new Intent(Cont.this,Donate.class);
            startActivity(i1);
        }
    });
}
public void init(){

}

public void onClickTest(View view){
    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
}

logcat的:

    04-28 01:22:41.928: W/EGL_genymotion(2203): eglSurfaceAttrib not implemented
04-28 01:22:47.028: W/EGL_genymotion(2203): eglSurfaceAttrib not implemented
04-28 01:22:49.188: W/EGL_genymotion(2203): eglSurfaceAttrib not implemented
04-28 01:22:50.924: D/AndroidRuntime(2203): Shutting down VM
04-28 01:22:50.924: W/dalvikvm(2203): threadid=1: thread exiting with uncaught exception (group=0xa4b87648)
04-28 01:22:50.928: E/AndroidRuntime(2203): FATAL EXCEPTION: main
04-28 01:22:50.928: E/AndroidRuntime(2203): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sadaka/com.example.sadaka.Cont}: android.view.InflateException: Binary XML file line #78: Error inflating class fragment
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.os.Looper.loop(Looper.java:137)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread.main(ActivityThread.java:5103)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.reflect.Method.invoke(Method.java:525)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at dalvik.system.NativeStart.main(Native Method)
04-28 01:22:50.928: E/AndroidRuntime(2203): Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class fragment
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.Activity.setContentView(Activity.java:1895)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at com.example.sadaka.Cont.onCreate(Cont.java:24)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.Activity.performCreate(Activity.java:5133)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
04-28 01:22:50.928: E/AndroidRuntime(2203):     ... 11 more
04-28 01:22:50.928: E/AndroidRuntime(2203): Caused by: java.lang.NullPointerException: name == null
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.VMClassLoader.findLoadedClass(Native Method)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:354)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.ClassLoader.loadClass(ClassLoader.java:491)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:436)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:255)
04-28 01:22:50.928: E/AndroidRuntime(2203):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
04-28 01:22:50.928: E/AndroidRuntime(2203):     ... 21 more
04-28 01:22:52.348: I/Process(2203): Sending signal. PID: 2203 SIG: 9
04-28 01:22:53.648: E/cutils-trace(2320): Error opening trace file: No such file or directory (2)
04-28 01:22:53.660: D/TilesManager(2320): Starting TG #0, 0xb85da558
04-28 01:22:53.660: D/TilesManager(2320): new EGLContext from framework: b838d3c8 
04-28 01:22:53.660: D/GLWebViewState(2320): Reinit shader
04-28 01:22:53.768: D/GLWebViewState(2320): Reinit transferQueue

清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sadaka"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<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"/>
    <permission 
        android:name="com.example.sadaka.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="com.example.sadaka.permission.MAPS_RECEIVE"/>
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000"
    android:required="true"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
        <meta-data 
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAZ4ntXyoqLud8mjORXQPuCUsQ9yTrLUD4"/>
        <meta-data 
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

        <activity
            android:name=".Splash"
            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=".MainActivity"
            android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.sadaka.MAINACTIVITY"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        </activity>
          <activity
            android:name=".Donate"
            android:label="@string/app_name" >
                <intent-filter>
            <action android:name="com.example.sadaka.DONATE"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        </activity>
         <activity
            android:name=".Zakat"
            android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.example.sadaka.ZAKAT"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
        </activity>
                 <activity
            android:name=".Inf"
            android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.example.sadaka.INF"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
        </activity>
                         <activity
            android:name=".Cont"
            android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.example.sadaka.CONT"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
        </activity>       
        <activity
            android:name=".About"
            android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.example.sadaka.ABOUT"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
        </activity>       
            </application>

</manifest>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您添加的片段XML不是googlemap片段,而是您刚刚制作的片段。

改变这一点:

<fragment 
    android:id="@+id/fr"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    />

<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"/>