簡體   English   中英

嘗試加載地圖時,MapView菜單項崩潰

[英]MapView menu item crashing when loading attempting to load map

從菜單中選擇地圖項時,我的應用程序崩潰。 我認為我做錯了兩件事(如果不是全部)之一。 1-在菜單切換語句中,我沒有正確調用新活動(地圖)。 2-我的地圖活動配置不正確。

FriendsApp.java(我排除了不必要的位):

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

我目前只是靜態地添加一些坐標來使其工作。

任何幫助表示贊賞。

新增清單:

    <?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="@string/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> 

您的<activity>元素必須位於您的<application>元素內。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM