我在现有项目中制作了谷歌地图应用程序

时间:2013-07-25 18:32:26

标签: android

我试图将谷歌地图集成到我现有的项目中。我制作了一个按钮,可以直接链接到谷歌地图。但是,当我点击该按钮时,我的应用程序崩溃了。另外在清单中我是否需要为地图添加意图过滤器?我已将它的意图过滤到DEFAULT。以下是清单

的代码
    `<?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="mom.abhhi.tripindia"
       android:versionCode="1"
       android:versionName="1.0" >
       <uses-sdk
       android:minSdkVersion="10"
       android:targetSdkVersion="17" />
      <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-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=".Splashactivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="mom.abhhi.tripindia.Home"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="mom.abhhi.tripindia.HOME" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <activity
        android:name="mom.abhhi.tripindia.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="mom.abhhi.tripindia.HAINACTIVITY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".About"
        android:label="@string/app_name" >
    </activity>

    <activity
        android:name=".Delhi"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mumbai"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Chennai"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kolkata"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Welcome1"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Place1"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Food1"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Food2"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Shop1"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DAksh"
        android:label="@string/app_name" >
    </activity>

    <activity
        android:name=".DBangla"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DIndia_Gate"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DJama"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DJantar"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DKod"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DLotus"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DQutub"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DRash"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DRed_Fort"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFBarbeque"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFBig"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFBukhara"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFHard_Rock"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFIce"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFMy_Bar"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFParikrama"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFPirates"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFStarbucks"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFUnderdoggs"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFWarehouse"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DFWhite"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSChand"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSDilli"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSJanpatH"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSKhan"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSLajpat"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSPahar"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSSaroj"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".DSSundar"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Welcome4"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Place4"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kphow"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Welcome2"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mali"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mbandra"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mele"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mgoi"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mjuhu"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mmarine"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mnari"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Msidhi"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mwater"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Plcae2"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfaer"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfaurus"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfcandies"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfdoor"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfglobal"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfirish"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfsmash"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mfspice"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Shop2"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mschor"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mscolaba"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mscraw"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Msfashion"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mshigh"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Msinorbit"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Mslinking"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Msoberoi"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kfami"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kfballu"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kfbhojo"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kfkewpie"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kfoh"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kpbirla"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kpeden"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kpmarble"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kpnicco"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kpvictoria"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Kscroad"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Ksda"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Ksforum"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Ksnew"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Ksox"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Food4"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Shop4"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Nearby"
        android:label="@string/app_name" >
    </activity>
  <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD3EED3R5nWdY9sizbPwThf05e1uGcPJls"/>

</application>

 </manifest>'

mainactivity.java

    `package mom.abhhi.tripindia;
     import android.os.Bundle;
     import android.support.v4.app.FragmentActivity;
     public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}
    }`

mainactivity.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" >
    <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />
    </RelativeLayout> `

mumbai.java

    `package mom.abhhi.tripindia;
     import android.app.Activity;
     import android.content.Intent;
     import android.os.Bundle;
     import android.view.View;
     import android.view.View.OnClickListener;
     import android.widget.RadioButton;
     public class Mumbai extends Activity implements OnClickListener {
    RadioButton rb;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mumbai);
    View welcome2Click = findViewById(R.id.welcome2);
    welcome2Click.setOnClickListener(this);
    View place2Click = findViewById(R.id.place2);
    place2Click.setOnClickListener(this);
    View food2Click = findViewById(R.id.food2);
    food2Click.setOnClickListener(this);
    View shop2Click = findViewById(R.id.shop2);
    shop2Click.setOnClickListener(this);

    View change2Click = findViewById(R.id.change2);
    change2Click.setOnClickListener(this);
    View map2Click = findViewById(R.id.mumbai);
    map2Click.setOnClickListener(this);

//  View near2Click = findViewById(R.id.near2);
    //near2Click.setOnClickListener(this);

}

@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.welcome2:
        Intent i = new Intent(this, Welcome2.class);
        startActivity(i);
        break;
    case R.id.place2:
        Intent i1 = new Intent(this, Plcae2.class);
        startActivity(i1);
        break;
    case R.id.food2:
        Intent i2 = new Intent(this, Food2.class);
        startActivity(i2);
        break;
    case R.id.shop2:
        Intent i3 = new Intent(this, Shop2.class);
        startActivity(i3);
        break;

    case R.id.change2:
        Intent i4 = new Intent(this, Home.class);
        startActivity(i4);
        break;
    case R.id.mumbai:
        Intent i5 = new Intent(this, MainActivity.class);
        startActivity(i5);
        break;
    /*case R.id.near2:
        Intent i7 = new Intent(this, Nearby.class);
        startActivity(i7);
        break;*/

    }
}


             }'

logcat行         07-25 20:03:52.011: E/Trace(1000): error opening trace file: No such file or directory (2) 07-25 20:03:54.081: D/dalvikvm(1000): GC_FOR_ALLOC freed 43K, 7% free 2627K/2796K, paused 101ms, total 104ms 07-25 20:03:54.181: D/dalvikvm(1000): GC_CONCURRENT freed 1K, 6% free 3070K/3240K, paused 14ms+15ms, total 92ms 07-25 20:03:54.501: I/Choreographer(1000): Skipped 36 frames! The application may be doing too much work on its main thread. 07-25 20:03:54.531: D/gralloc_goldfish(1000): Emulator without GPU emulation detected. 07-25 20:04:00.140: D/dalvikvm(1000): GC_FOR_ALLOC freed 204K, 10% free 2941K/3268K, paused 233ms, total 261ms 07-25 20:04:00.200: I/dalvikvm-heap(1000): Grow heap (frag case) to 3.598MB for 640016-byte allocation 07-25 20:04:00.660: D/dalvikvm(1000): GC_CONCURRENT freed <1K, 9% free 3565K/3896K, paused 10ms+52ms, total 459ms 07-25 20:04:01.000: D/dalvikvm(1000): GC_FOR_ALLOC freed <1K, 9% free 3565K/3896K, paused 178ms, total 178ms 07-25 20:04:01.101: I/dalvikvm-heap(1000): Grow heap (frag case) to 4.970MB for 1440016-byte allocation 07-25 20:04:01.360: D/dalvikvm(1000): GC_CONCURRENT freed 0K, 7% free 4972K/5304K, paused 28ms+5ms, total 246ms 07-25 20:04:20.260: D/dalvikvm(1000): GC_FOR_ALLOC freed 633K, 14% free 5001K/5800K, paused 200ms, total 239ms 07-25 20:04:20.390: I/dalvikvm-heap(1000): Grow heap (frag case) to 6.096MB for 1150516-byte allocation 07-25 20:04:20.650: D/dalvikvm(1000): GC_CONCURRENT freed 465K, 19% free 5659K/6924K, paused 12ms+36ms, total 259ms 07-25 20:04:21.500: D/AndroidRuntime(1000): Shutting down VM 07-25 20:04:21.511: W/dalvikvm(1000): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 07-25 20:04:21.740: E/AndroidRuntime(1000): FATAL EXCEPTION: main 07-25 20:04:21.740: E/AndroidRuntime(1000): java.lang.RuntimeException: Unable to start activity ComponentInfo{mom.abhhi.tripindia/mom.abhhi.tripindia.Mumbai}: java.lang.NullPointerException 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread.access$600(ActivityThread.java:141) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.os.Handler.dispatchMessage(Handler.java:99) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.os.Looper.loop(Looper.java:137) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-25 20:04:21.740: E/AndroidRuntime(1000): at java.lang.reflect.Method.invokeNative(Native Method) 07-25 20:04:21.740: E/AndroidRuntime(1000): at java.lang.reflect.Method.invoke(Method.java:511) 07-25 20:04:21.740: E/AndroidRuntime(1000): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 07-25 20:04:21.740: E/AndroidRuntime(1000): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-25 20:04:21.740: E/AndroidRuntime(1000): at dalvik.system.NativeStart.main(Native Method) 07-25 20:04:21.740: E/AndroidRuntime(1000): Caused by: java.lang.NullPointerException 07-25 20:04:21.740: E/AndroidRuntime(1000): at mom.abhhi.tripindia.Mumbai.onCreate(Mumbai.java:31) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.Activity.performCreate(Activity.java:5104) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 07-25 20:04:21.740: E/AndroidRuntime(1000): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 07-25 20:04:21.740: E/AndroidRuntime(1000): ... 11 more

0 个答案:

没有答案