Balaji S
Balaji S

Reputation: 174

RuntimeException in Android studio, on using maps

I am trying to use maps, and am a newbie to java/android. I allowed AS to generate the xml and stuff.

I am using intent and 2 activity and need the 2nd activity to load maps.

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

The code used is the basic code that is generated by AS.

The launcher activity code as follows; public class MainActivity extends 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);
}
}

The Manifest file is as follows;

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

I have been searching online for about a couple of days, but I am unable to comprehend the information that I read online. Could you help me out?

The error log is as follows; :app:generateDebugBuildConfig [Fatal Error] :5:79: The prefix "android" for attribute "android:name" associated with an element type "uses-permission" is not bound.

FAILURE: Build failed with an exception.

BUILD FAILED

Upvotes: 0

Views: 227

Answers (1)

Snoobie
Snoobie

Reputation: 760

I think you are missing some steps, for example in your AndroidManifest.xml you should use 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" />

Here a good tutorial very well explain.

Hope it helps,

Upvotes: 1

Related Questions