Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot seem to get the buttons to open a new MapActivity
    text
    copied!<p>I've been playing around with this for some time now and am hoping that someone smarter than I will be able to help. My boss has given me an opportunity to learn to develop Android apps and I'm struggling with this one issue. I need to build several apps with multiple activities but can't seem to get past this point. I'm sure it's a problem in my coding, but with so many different ways of doing things, I'm a little confused at this point. </p> <p>I am building an app that opens a Main activity with two buttons on the page. One is the close button and works fine. I want the next button to open a mapActivity that is set to my campus' location. I am not a student working on a project I just work for a community college. ;-)</p> <p>What's really wierd is that the EXACT same google.maps code works fine by itself. I just can't get the button to open the Activity without crashing.</p> <p>Here is my manifest.xml, main.xml, my main.java, Map.java and map.xml. would you please comment and point me in the right direction?</p> <p>Thanks in advance, Dave</p> <p>here are two errors:</p> <pre><code>11-21 14:50:58.968: W/dalvikvm(437): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 11-21 14:50:58.978: E/AndroidRuntime(437): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=edu.mtsac.mapproject.MAP } </code></pre> <p>This says the Activity was not found but I can see it in my source files, and in the manifest here:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="edu.mtsac.mapproject" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;uses-library android:name="com.google.android.maps" /&gt; &lt;activity android:label="@string/app_name" android:name=".Main" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;!-- map activity --&gt; &lt;activity android:label="Map" android:name=".Map" &gt; &lt;intent-filter &gt; &lt;action android:name="edu.mtsac.mapproject.MAP" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>My Main.xml and Map.xml files are simple:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/mapBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="Map" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Map.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="0jevUfyLD_b1Eikgpm_mo7KVDspzhPJdRDDaxEw" android:clickable="true" android:enabled="true" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>the Main.java</p> <pre><code>package edu.mtsac.mapproject; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button mapBtn = (Button) findViewById(R.id.mapBtn); mapBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(Main.this, Map.class)); } }); Button closeBtn = (Button) findViewById(R.id.closeBtn); closeBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); };// end onCreate() } </code></pre> <p>and lastly the Map.java</p> <pre><code>package edu.mtsac.mapproject; import android.os.Bundle; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; public class Map extends MapActivity { MapController mc; GeoPoint p; MapView mapview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); mapview = (MapView) findViewById(R.id.mapView); mapview.displayZoomControls(true); mapview.setBuiltInZoomControls(true); mapview.setSatellite(true); mc = mapview.getController(); String coord[] = { "34.047517", "-117.847050" }; double lat = Double.parseDouble(coord[0]); double lng = Double.parseDouble(coord[1]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); mapview.invalidate(); } @Override protected boolean isRouteDisplayed() { return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload