Android studio中的RuntimeException,使用地图

时间:2016-01-27 00:24:35

标签: android google-maps android-studio

我正在尝试使用地图,并且是java / android的新手。我允许AS生成xml和东西。

我正在使用intent和2活动,需要第二个活动来加载地图。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

使用的代码是AS生成的基本代码。

启动器活动代码如下;     公共类MainActivity扩展了AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    //    addButtonListner();
}

public void sendMessage(View view) {
    Intent intent = new Intent(this, MapsActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra("com.home.jop.Message", message);
    startActivity(intent);
}
}

Manifest文件如下;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://schemas.android.com/apk/res/android"
package="jop.omgodess">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyDrCYMoDWVPlcOiQAaaww7hXwW2fFqGZrQ" />
    <activity
        android:name="jop.omgodess.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>
    <activity android:name="jop.omgodess.MapsActivity"
        android:label="@string/title_activity_maps">
        <meta-data android:name="android.support.PARENT_ACTIVITY"
            android:value="jop.omgodess.MainActivity" />
    </activity>
</application>
</manifest>

我在网上搜索了大约几天,但我无法理解我在网上阅读的信息。你能救我一下吗?

错误日志如下; :应用:generateDebugBuildConfig [致命错误]:5:79:前缀&#34; android&#34; for attribute&#34; android:name&#34;与元素类型相关联&#34; uses-permission&#34;不受约束。

失败:构建因异常而失败。

  • 出了什么问题: 无法从C:\ Users \ Sony vaio \ AndroidStudioProjects \ OMGodess \ app \ src \ main \ AndroidManifest.xml

  • 读取packageName
  • 尝试: 使用--info或--debug选项运行以获得更多日志输出。

  • 例外情况是: java.lang.RuntimeException:无法从C:\ Users \ Sony vaio \ AndroidStudioProjects \ OMGodess \ app \ src \ main \ AndroidManifest.xml读取packageName 在com.android.builder.core.VariantConfiguration.getPackageFromManifest(VariantConfiguration.java:945) 在com.android.builder.core.VariantConfiguration.getOriginalApplicationId(VariantConfiguration.java:740) 在com.android.build.gradle.tasks.GenerateBuildConfig $ _ConfigAction_execute_closure1.doCall(GenerateBuildConfig.groovy:170) 在com.android.build.gradle.tasks.GenerateBuildConfig $ _ConfigAction_execute_closure1.doCall(GenerateBuildConfig.groovy) 在org.gradle.api.internal.ConventionAwareHelper $ 2.getValue(ConventionAwareHelper.java:84) 在org.gradle.api.internal.ConventionAwareHelper $ MappedPropertyImpl.getValue(ConventionAwareHelper.java:136) 在org.gradle.api.internal.ConventionAwareHelper.getConventionValue(ConventionAwareHelper.java:114) at com.android.build.gradle.tasks.GenerateBuildConfig_Decorated.getBuildConfigPackageName(Unknown Source) 在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ PropertyInfo $ 4.create(AnnotationProcessingTaskFactory.java:460) 在org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:166) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ PropertyInfo.getValue(AnnotationProcessingTaskFactory.java:458) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ Validator.validate(AnnotationProcessingTaskFactory.java:276) 在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:41) 在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) 在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) 在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 在org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310) 在org.gradle.execution.taskgraph.Abs​​tractTaskPlanExecutor $ TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) at org.gradle.execution.taskgraph.Abs​​tractTaskPlanExecutor $ TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63) at org.gradle.execution.taskgraph.Abs​​tractTaskPlanExecutor $ TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88) 在org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62) 在org.gradle.execution.DefaultBuildExecuter.access $ 200(DefaultBuildExecuter.java:23) 在org.gradle.execution.DefaultBuildExecuter $ 2.proceed(DefaultBuildExecuter.java:68) 在org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55) 在org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149) 在org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106) 在org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86) at org.gradle.launcher.exec.InProcessBuildActionExecuter $ DefaultBuildController.run(InProcessBuildActionExecuter.java:90) 在org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:54) 在org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28) 在org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:49) 在org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.ForwardClientInput $ 2.call(ForwardClientInput.java:74) 在org.gradle.launcher.daemon.server.exec.ForwardClientInput $ 2.call(ForwardClientInput.java:72) 在org.gradle.util.Swapper.swap(Swapper.java:38) 在org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66) 在org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71) 在org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41) 在org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy $ 1.run(StartBuildOrRespondWithBusy.java:50) 在org.gradle.launcher.daemon.server.DaemonStateCoordinator $ 1.run(DaemonStateCoordinator.java:246) at org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54) 在org.gradle.internal.concurrent.StoppableExecutorImpl $ 1.run(StoppableExecutorImpl.java:40)

建立失败

1 个答案:

答案 0 :(得分:1)

我认为您错过了一些步骤,例如在AndroidManifest.xml中您应该使用com.google.android.maps.v2.API_KEY

<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

这里有一个很好的tutorial解释。

希望它有所帮助,