使用谷歌地图v2编码Android应用程序 - 立即崩溃

时间:2012-12-22 18:39:38

标签: android google-maps google-maps-api-2

我是应用程序编程和编程的新手。我还在学校读计算机科学(我是sophmore)。所以请放轻松我。我讨厌在论坛上抨击。

我的问题是我的应用程序将使用谷歌地图作为主窗口立即崩溃。我已经在下面发布了我的所有代码,我正在寻找任何有关我可能缺少的帮助以启动和运行此应用程序(或者它不会立即崩溃)。

有些事情可能是错的:

1)我现在正在使用SHA1调试密钥进行此测试阶段。这是对的吗?

2)我是否需要与java中的“GoogleMap”类型进行通信以设置起始位置或其他内容?

3)我正在我的手机(Galaxy SIII)上进行测试,该手机过去曾在简单的布局上工作,但可能测试这个谷歌地图应用程序需要手机无法提供的身份验证吗?

到目前为止,我发现一些有用的链接: https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

Google Maps Android API v2 - Sample Code crashes

设置注意事项:我已将android-support-v4.jar和google-play-services.jar添加到我的参考库中。 属性 - > Java构建路径,库

现在,下面,这是我到目前为止的所有代码!

Java文件(Main.java):

package com.MYDOMAINNAME.www;

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.main);
}
}

xml文件(主要布局):

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>

程序清单:

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<permission
     android:name="com.MYDOMAINNAME.www.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
<uses-permission  android:name="com.MYDOMAINNAME.www.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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"/>

<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" >
    <uses-library android:name= "com.google.android.maps" />
    <activity
        android:name="com.MYDOMAINNAME.www.Main"
        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.maps.v2.API_KEY"
    android:value="MY SHA1 DEBUG KEY"/>
</application>
</manifest>

所以我会问,有什么我需要添加或减去才能实现这一目标吗?

非常感谢!

Log Cat:

12-22 14:45:28.482: E/Trace(10174): error opening trace file: No such file or directory (2)
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapUtilization:0.25
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapIdealFree:8388608
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapConcurrentStart:2097152
12-22 14:45:28.502: D/AndroidRuntime(10174): Shutting down VM
12-22 14:45:28.502: W/dalvikvm(10174): threadid=1: thread exiting with uncaught exception (group=0x4155e438)
12-22 14:45:28.512: E/AndroidRuntime(10174): FATAL EXCEPTION: main
12-22 14:45:28.512: E/AndroidRuntime(10174): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.MYDOMAINAME.www/com.MYDOMAINAME.www.MainActivity}: java.lang.ClassNotFoundException: com.MYDOMAINAME.www.MainActivity
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2012)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread.access$700(ActivityThread.java:139)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.os.Looper.loop(Looper.java:137)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread.main(ActivityThread.java:4918)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at java.lang.reflect.Method.invokeNative(Native Method)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at java.lang.reflect.Method.invoke(Method.java:511)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at dalvik.system.NativeStart.main(Native Method)
12-22 14:45:28.512: E/AndroidRuntime(10174): Caused by: java.lang.ClassNotFoundException: com.MYDOMAINAME.www.MainActivity
12-22 14:45:28.512: E/AndroidRuntime(10174):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
12-22 14:45:28.512: E/AndroidRuntime(10174):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2003)
12-22 14:45:28.512: E/AndroidRuntime(10174):    ... 11 more

1 个答案:

答案 0 :(得分:1)

您为Main的java文件命名了什么?它应该是Main.java而不是MainActivity.java 如果你查看日志,这一行12-22 14:04:16.043: E/AndroidRuntime(9154): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gotonight.www/com.gotonight.www.MainActivity}: java.lang.ClassNotFoundException: com.gotonight.www.MainActivity已尝试查找com.gotonight.www.MainActivity,但您的主要课程为com.gotonight.www.Main