不幸的是,[app] 在加载 google 个地图时已停止

Unfortunately, [app] has stopped while loading google maps

我正在创建一个包含登录的 android 应用程序,在登录页面后,我已授予对 Google 地图的访问权限。当我首先尝试 运行 google 地图而不使用登录地图时,它工作正常但是当我在其中引入登录页面时出现错误“不幸的是应用程序已停止”

这是我的 Main_activity.java

package com.example.maps;



   import java.io.IOException;

   import org.xmlpull.v1.XmlPullParserException;

 import android.support.v7.app.ActionBarActivity;
 import android.text.InputType;
 import android.app.AlertDialog;
import android.content.Intent;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ToggleButton;

 public class MainActivity extends ActionBarActivity {


    Button chkcmd ;
   EditText id;
   EditText password;
    ToggleButton passTog;


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

    chkcmd = (Button) findViewById(R.id.bLOGIN);
    id = (EditText) findViewById(R.id.etID);
    password = (EditText) findViewById(R.id.etPASSWORD);
     passTog = (ToggleButton) findViewById(R.id.tbCHECK);


     passTog.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(passTog.isChecked()){
                    password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);      
                    id.setInputType(InputType.TYPE_CLASS_TEXT);
                }
                else{
                    password.setInputType(InputType.TYPE_CLASS_TEXT);   
                    id.setInputType(InputType.TYPE_CLASS_TEXT);
                }
            }
        });


     chkcmd.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String checkID = id.getText().toString();
                String checkPASS = password.getText().toString();
                if(checkID.contentEquals("raubid") && checkPASS.contentEquals("helpme") ){

                    Intent openStartingPoint = new Intent("com.example.goon.Maps");
                    startActivity(openStartingPoint);
                }
                else {


                    AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(MainActivity.this);
                    // Setting Dialog Title
                    alertDialog2.setTitle("Error");

                    // Setting Dialog Message
                    alertDialog2.setMessage("Invalid Login Details");
                    alertDialog2.setNeutralButton("Close", null).show();
                    }
                }

            });




}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

这是我的 Maps.java

 package com.example.maps;
 import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;

public class Maps extends FragmentActivity  {

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

  }

activity_main.xml

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

  <fragment
        android:id="@+id/map"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

我的login.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.locateme.MainActivity" >



  <EditText
    android:id="@+id/etID"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Device Id"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:password="true" />

    <EditText
    android:id="@+id/etPASSWORD"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Device Password"
    android:layout_gravity="center"
    android:layout_marginTop="70dp"
    android:password="true" />

  <Button
   android:id="@+id/bLOGIN"
   android:layout_width="220dp"
   android:layout_height="wrap_content"
   android:layout_alignLeft="@+id/etCommands"
   android:layout_below="@+id/etCommands"
   android:layout_marginTop="110dp"
   android:text="Login" />

  <ToggleButton
   android:id="@+id/tbCHECK"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignBaseline="@+id/bLOGIN"
   android:layout_alignBottom="@+id/bLOGIN"
   android:layout_alignRight="@+id/etPASSWORD"
   android:text="ToggleButton" />

</RelativeLayout>

和我的AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maps"
android:versionCode="1"
android:versionName="1.0" >

  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
 <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="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=".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.gms.version"
android:value="@integer/google_play_services_version" />
  <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyArP83hWnigUMczcwT8J56TJtvOdcCSmRA"/>
  <activity
        android:name=".Maps"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

  </application>

</manifest>

记录猫的详细信息

01-17 09:45:45.038: D/dalvikvm(23915): Late-enabling CheckJNI 01-17 09:45:45.398: D/TextLayoutCache(23915): Using debug level: 0 - Debug Enabled: 0 01-17 09:45:45.428: D/libEGL(23915): loaded /system/lib/egl/libGLES_android.so 01-17 09:45:45.428: D/libEGL(23915): loaded /system/lib/egl/libEGL_adreno200.so 01-17 09:45:45.438: D/libEGL(23915): loaded /system/lib/egl/libGLESv1_CM_adreno200.so 01-17 09:45:45.438: D/libEGL(23915): loaded /system/lib/egl/libGLESv2_adreno200.so 01-17 09:45:45.498: D/OpenGLRenderer(23915): Enabling debug mode 0 01-17 09:45:47.878: D/dalvikvm(23915): GC_CONCURRENT freed 177K, 3% free 9070K/9287K, paused 2ms+3ms 01-17 09:46:04.788: D/AndroidRuntime(23915): Shutting down VM 01-17 09:46:04.788: W/dalvikvm(23915): threadid=1: thread exiting with uncaught exception (group=0x2b542210) 01-17 09:46:04.798: E/AndroidRuntime(23915): FATAL EXCEPTION: main 01-17 09:46:04.798: E/AndroidRuntime(23915): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.goon.Maps } 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.app.Activity.startActivityForResult(Activity.java:3190) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.app.Activity.startActivity(Activity.java:3297) 01-17 09:46:04.798: E/AndroidRuntime(23915): at com.example.maps.MainActivity.onClick(MainActivity.java:68) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.view.View.performClick(View.java:3534) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.view.View$PerformClick.run(View.java:14263) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.os.Handler.handleCallback(Handler.java:605) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.os.Handler.dispatchMessage(Handler.java:92) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.os.Looper.loop(Looper.java:137) 01-17 09:46:04.798: E/AndroidRuntime(23915): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-17 09:46:04.798: E/AndroidRuntime(23915): at java.lang.reflect.Method.invokeNative(Native Method) 01-17 09:46:04.798: E/AndroidRuntime(23915): at java.lang.reflect.Method.invoke(Method.java:511) 01-17 09:46:04.798: E/AndroidRuntime(23915): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 01-17 09:46:04.798: E/AndroidRuntime(23915): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-17 09:46:04.798: E/AndroidRuntime(23915): at dalvik.system.NativeStart.main(Native Method) 01-17 09:46:06.238: D/dalvikvm(23915): Debugger has detached; object registry had 1 entries 01-17 09:49:39.638: D/dalvikvm(23915): Debugger has detached; object registry had 1 entries 01-17 09:49:41.798: D/dalvikvm(23915): Debugger has detached; object registry had 1 entries 01-17 09:50:35.068: D/dalvikvm(23915): Debugger has detached; object registry had 1 entries 01-17 10:00:30.428: D/OpenGLRenderer(24193): Enabling debug mode 0 01-17 10:00:30.598: D/dalvikvm(24193): GC_CONCURRENT freed 182K, 3% free 9064K/9287K, paused 3ms+61ms 01-17 10:00:48.028: D/AndroidRuntime(24193): Shutting down VM 01-17 10:00:48.028: W/dalvikvm(24193): threadid=1: thread exiting with uncaught exception (group=0x2b542210) 01-17 10:00:48.038: E/AndroidRuntime(24193): FATAL EXCEPTION: main 01-17 10:00:48.038: E/AndroidRuntime(24193): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.goon.Maps } 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.app.Activity.startActivityForResult(Activity.java:3190) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.app.Activity.startActivity(Activity.java:3297) 01-17 10:00:48.038: E/AndroidRuntime(24193): at com.example.maps.MainActivity.onClick(MainActivity.java:68) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.view.View.performClick(View.java:3534) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.view.View$PerformClick.run(View.java:14263) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.os.Handler.handleCallback(Handler.java:605) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.os.Handler.dispatchMessage(Handler.java:92) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.os.Looper.loop(Looper.java:137) 01-17 10:00:48.038: E/AndroidRuntime(24193): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-17 10:00:48.038: E/AndroidRuntime(24193): at java.lang.reflect.Method.invokeNative(Native Method) 01-17 10:00:48.038: E/AndroidRuntime(24193): at java.lang.reflect.Method.invoke(Method.java:511) 01-17 10:00:48.038: E/AndroidRuntime(24193): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 01-17 10:00:48.038: E/AndroidRuntime(24193): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-17 10:00:48.038: E/AndroidRuntime(24193): at dalvik.system.NativeStart.main(Native Method) 01-17 10:00:58.828: I/Process(24193): Sending signal. PID: 24193 SIG: 9 01-17 10:01:05.798: D/TextLayoutCache(24240): Using debug level: 0 - Debug Enabled: 0 01-17 10:01:05.858: D/libEGL(24240): loaded /system/lib/egl/libGLES_android.so 01-17 10:01:05.868: D/libEGL(24240): loaded /system/lib/egl/libEGL_adreno200.so 01-17 10:01:05.868: D/libEGL(24240): loaded /system/lib/egl/libGLESv1_CM_adreno200.so 01-17 10:01:05.868: D/libEGL(24240): loaded /system/lib/egl/libGLESv2_adreno200.so 01-17 10:01:05.908: D/OpenGLRenderer(24240): Enabling debug mode 0 01-17 10:01:05.988: D/dalvikvm(24240): GC_CONCURRENT freed 188K, 4% free 9068K/9351K, paused 3ms+6ms 01-17 10:01:26.148: D/OpenGLRenderer(24240): Flushing caches (mode 0) 01-17 10:02:30.408: D/TextLayoutCache(24381): Using debug level: 0 - Debug Enabled: 0 01-17 10:02:30.458: D/libEGL(24381): loaded /system/lib/egl/libGLES_android.so 01-17 10:02:30.468: D/libEGL(24381): loaded /system/lib/egl/libEGL_adreno200.so 01-17 10:02:30.498: D/libEGL(24381): loaded /system/lib/egl/libGLESv1_CM_adreno200.so 01-17 10:02:30.498: D/libEGL(24381): loaded /system/lib/egl/libGLESv2_adreno200.so 01-17 10:02:31.108: D/OpenGLRenderer(24381): Enabling debug mode 0 01-17 10:02:32.838: D/dalvikvm(24381): GC_CONCURRENT freed 176K, 3% free 9071K/9287K, paused 5ms+1ms 01-17 10:02:45.428: D/AndroidRuntime(24381): Shutting down VM 01-17 10:02:45.428: W/dalvikvm(24381): threadid=1: thread exiting with uncaught exception (group=0x2b542210) 01-17 10:02:45.438: E/AndroidRuntime(24381): FATAL EXCEPTION: main 01-17 10:02:45.438: E/AndroidRuntime(24381): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.goon.Maps } 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.app.Activity.startActivityForResult(Activity.java:3190) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.app.Activity.startActivity(Activity.java:3297) 01-17 10:02:45.438: E/AndroidRuntime(24381): at com.example.maps.MainActivity.onClick(MainActivity.java:68) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.view.View.performClick(View.java:3534) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.view.View$PerformClick.run(View.java:14263) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.os.Handler.handleCallback(Handler.java:605) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.os.Handler.dispatchMessage(Handler.java:92) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.os.Looper.loop(Looper.java:137) 01-17 10:02:45.438: E/AndroidRuntime(24381): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-17 10:02:45.438: E/AndroidRuntime(24381): at java.lang.reflect.Method.invokeNative(Native Method) 01-17 10:02:45.438: E/AndroidRuntime(24381): at java.lang.reflect.Method.invoke(Method.java:511) 01-17 10:02:45.438: E/AndroidRuntime(24381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 01-17 10:02:45.438: E/AndroidRuntime(24381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 01-17 10:02:45.438: E/AndroidRuntime(24381): at dalvik.system.NativeStart.main(Native Method)

这是我的应用程序的代码。任何帮助都会很深 appreciated.Thanks

这里:

Intent openStartingPoint = new Intent("com.example.goon.Maps");

您可能遇到以下错误:

ActivityNotFoundException: No Activity found to handle Intent

因为 AndroidManifest.xml 中没有可用的操作 com.example.goon.Maps 操作。

Maps Activity 操作更改为 com.example.goon.Maps :

<intent-filter>
       <action android:name="com.example.goon.Maps" /> 
</intent-filter>

现在使用 com.example.goon.Maps 动作开始 Maps Activity.

您也可以开始 Maps Activity 使用 class 姓名 :

Intent intent=new Intent(v.getContext(),Maps.class);
v.getContext().startActivity(intent);