Search code examples
androidgoogle-mapsgoogle-maps-api-2

Coding android app with google maps v2 - Crashes immediately


I am new to app programming, and programming in general. I am still in school for computer science (i'm a sophmore). So please take it easy on me. I hate getting bashed on forums.

My problem is that my app, which will use google maps as the main window crashes immediately. I have posted all my code below, and I am looking for any help to what I might be missing to get this app up and running (or so it does not crash immediately).

A couple things might be wrong:

1) I am now using the SHA1 debug key for this testing stage. Is this right?

2) Do I need to communicate with a type 'GoogleMap' in java to set starting location or anything?

3) I am testing this on my phone (Galaxy SIII) which has worked in the past on simple layouts, but might testing this google maps app need authentication that the phone cannot give?

A couple links I found helpful, up until now: https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

Google Maps Android API v2 - Sample Code crashes

Notes on setup: I have added android-support-v4.jar and google-play-services.jar to my reference libraries. Properties -> Java Build Path, Libraries

Now, Below, this is all the code I have so far!

Java file (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 file (main layout):

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

program manifest:

<?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>

So I would ask, is there anything I need to add or subtract to get this going?

Thanks a bunch!

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

Solution

  • What did you name your java file for Main? It should be Main.java not MainActivity.java.
    If you look at the log , this line 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
    its trying to find
    com.gotonight.www.MainActivity but your Main class is com.gotonight.www.Main