2012-04-22 65 views
1

我有兩個類,Syros1ActivityMapActivity 。 在第一項活動中(Syros1Activity)我有一些按鈕。第二個是Map。 我想連接其中一個按鈕,當我選擇它時啓動MapActivity。這裏是我的代碼:Android程序添加地圖活動

MapActivity:

import android.os.Bundle; 
import com.view.View; 
import com.google.android.maps.MapView; 

public class MapActivity { 

public void onCreate(Bundle savedInstanceState) { 
    super.**onCreate**(savedInstanceState); --->Here i get a mistake The method onCreate(Bundle) is undefined for the type Object 
    setContentView(R.layout.maplayout); 
    MapView mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
} 

protected boolean isRouteDisplayed(){ return false;} 
private void setBuiltInZoomControls(boolean b) { 
    throw new UnsupportedOperationException("Not yet implemented"); 
} 

private void setBuiltInZoomControls(boolean b) { 
    throw new UnsupportedOperationException("Not yet implemented"); 
} 

private MapView findViewById(int mapview) { 
    // TODO Auto-generated method stub 
return null; 
} 

private void setContentView(int maplayout) { 
    // TODO Auto-generated method stub 
} 
} 

Syros1Activity:

import android.app.Activity; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.Button; 
import android.widget.ProgressBar; 
import android.widget.Toast; 
import android.view.View; 
import android.view.View.OnClickListener; 


public class Syros1Activity extends Activity implements OnClickListener{ 
    private static final int PROGRESS = 0x1; 
    private ProgressBar mProgress; 
    private int mProgressStatus = 0; 

    private static final String DEBUG_TAG = null; 
    private static final OnClickListener OnClickListener = null; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button btn11 = (Button) findViewById(R.id.Button11); 
       btn11.setOnClickListener(this); 


     Button btn12 = (Button) findViewById(R.id.Button12); 
       btn12.setOnClickListener(this); 

     Button btn13 = (Button) findViewById(R.id.Button13); 
       btn13.setOnClickListener(this); 

     Button btn21 = (Button) findViewById(R.id.Button21); 
       btn21.setOnClickListener(this); 

     Button btn22 = (Button) findViewById(R.id.Button22); 
       btn22.setOnClickListener(this); 

     Button btn23 = (Button) findViewById(R.id.Button23); 
       btn23.setOnClickListener(this); 

    } 


    public void getLocation (Location location ) { 
     try { 
      LocationManager locMgr = (LocationManager) 
       getSystemService(LOCATION_SERVICE); 
      Location recentLoc = locMgr. 
       getLastKnownLocation(LocationManager.GPS_PROVIDER); 
      Log.i(DEBUG_TAG, "loc: " + recentLoc.toString()); 

      } 
    catch (Exception e) { 
     Log.e(DEBUG_TAG,"Location failed", e); 

    } 

    } 

    public void onClick(View v) { 
     if (v.getId() == R.id.Button11){ 
      Toast.makeText(this, "Loading Google Map", Toast.LENGTH_SHORT) 
      .show(); 
      Intent intent =new Intent(); 
      intent.setClass(getApplicationContext(),MapActivity.class); 
      startActivity(intent); 
     } 



     else if(v.getId() == R.id.Button12){ 
      Toast.makeText(this, "Loading Sights", Toast.LENGTH_SHORT) 
      .show(); 
     } 
     else if(v.getId() == R.id.Button13){ 
      Toast.makeText(this, "Loading Beach", Toast.LENGTH_SHORT) 
      .show(); 
    } 
     else if(v.getId() == R.id.Button21){ 
      Toast.makeText(this, "Loading Bars", Toast.LENGTH_SHORT) 
      .show(); 
    } 
     else if(v.getId() == R.id.Button21){ 
     Toast.makeText(this, "Loading Bars", Toast.LENGTH_SHORT) 
     .show(); 
    } 
     else if(v.getId() == R.id.Button22){ 
      Toast.makeText(this, "Loading Restaurant", Toast.LENGTH_SHORT) 
      .show(); 
    } 
     else if(v.getId() == R.id.Button23){ 
      Toast.makeText(this, "Loading Developer Information", Toast.LENGTH_SHORT) 
      .show(); 
    } 
    } 



    public static OnClickListener getOnclicklistener() { 
     return OnClickListener; 
    } 
} 

回答

0

重命名MapActivity類,稱之爲MyMapActivity

則這樣定義類,public class MyMapActivity extends MapActivity

+

確保您使用谷歌API中的一個,所以你可以使用谷歌地圖圖書館

+

確保您在AndroidManifest.xml(下應用標籤)文件,以便使用谷歌添加此代碼地圖

<uses-library android:required="true" android:name="com.google.android.maps" /> 
+0

謝謝你現在是好的這個問題。 – Baggelisrouk 2012-04-22 20:27:01

+0

歡迎您,您可以將此標記爲答案,對其他人有用,您的問題也一樣,祝您好運! – 2012-04-22 20:29:35

+0

現在,當我選擇按鈕,我已經把mymapactivity開始我得到不幸的是,已停止。 對此有何幫助? – Baggelisrouk 2012-04-22 20:30:23

0

沒有你在清單文件中使用此權限

<uses-permission android:name="android.permission.INTERNET" /> 

如果沒有在您的清單文件中提及它的應用程序標籤