MapView menu item crashing when loading attempting to load map
My app is crashing when the map item is selected from my menu. I think I am doing one of two things (if not both) wrong. 1 - In my menu switch statement I'm not calling the new activity (map) correctly. 2 - My map activity isn't configured correctly.
FriendsApp.java (I excluded unnecessary bits):
public class FriendApp extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://example.com/myfrienddash.php");
mWebView.setWebViewClient(new FriendWebViewClient());
}
//Tell main menu what to do when elements are clicked
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case FRIENDS:
mWebView.loadUrl("http://example.com/myfrienddash2.php");
return true;
case MAP:
Intent friendMap = new Intent(FriendApp.this, FriendMaps.class);
startActivity(friendMap);
return true;
case SEARCH:
mWebView.loadUrl("http://example.com/myfrienddash3.php");
return true;
case INFO:
mWebView.loadUrl("http://example.com/myfrienddash4.php");
return true;
case QUIT:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}}
FriendMaps.java:
public class FriendMaps extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
BuoyItemizedOverlay itemizedoverlay = new BuoyItemizedOverlay(drawable, mapView.getContext());
double longitude = 44.5;
double latitude = -63.4;
GeoPoint point = new GeoPoint((int)(longitude * 1E6),
(int)(latitude * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "what you talking aboot", "eh!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
//Not using route feature so return false (must be set)
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
I am currently just statically adding some coordinates to get it working.
Any help is appreciated.
Added Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.friendapp"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@strin开发者_如何学JAVAg/app_name">
<activity android:name=".FriendApp"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".FriendMaps" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" />
</manifest>
Your <activity>
element needs to be inside your <application>
element.
精彩评论