2011-04-10 18 views
0
が、私はそれにマップを追加したとき、それがクラッシュするものの、[OK]を行ってタブを作成するための多くの方法を試してみましたねえ、私はこの男がここで何をしたか試してみました

TABS TOタブが表示されます。コードは以下の通りです:AndroidのMAPは

import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import android.widget.TabHost.TabContentFactory;

import com.google.android.maps.MapActivity; import com.google.android.maps.MapView;

パブリッククラスタブMapActivityがOnTabChangeListener {

private static final String HOME_TAG = "Home"; 
private static final String PLAYERS_TAG = "Players"; 
private static final String MAP_TAG = "Map"; 
private static final String TICKET_TAG = "Ticket"; 

private TabHost tabHost; 
private MapView mapView; 

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

    tabHost = (TabHost)findViewById(android.R.id.tabhost); 
    tabHost.setup(); 
    tabHost.setOnTabChangedListener(this); 

    mapView = (MapView)findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
    mapView.postInvalidate(); 

    tabHost.addTab(tabHost.newTabSpec(HOME_TAG).setIndicator("Home").setContent(new Intent(this, Home.class))); 
    tabHost.addTab(tabHost.newTabSpec(PLAYERS_TAG).setIndicator("Players").setContent(new Intent(this, Players.class))); 
    tabHost.addTab(tabHost.newTabSpec(MAP_TAG).setIndicator("Venue").setContent(new TabContentFactory() { 

     public View createTabContent(String arg0) { 
      return mapView; 
     } 
    })); 

    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
    { 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#00CC33")); 
    } 

    tabHost.getTabWidget().setCurrentTab(0); 
    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#3399FF")); 
} 

public void onTabChanged(String tabId) { 
    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
     { 
      tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#00CC33")); 
     } 
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#3399FF")); 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 

}

私のマニフェストを実装延び:

<application android:icon="@drawable/englandrugbyrose" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"> 
    <activity android:name=".Splash" 
       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=".Tabs" /> 
    <activity android:name=".Home" /> 
    <activity android:name=".Players" /> 
    <activity android:name=".Tickets" /> 
    <activity android:name=".Map" /> 

    <uses-library android:name="com.google.android.maps" /> 

</application> 
    <uses-sdk android:minSdkVersion="10" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

Btw、私のXMLは、コンテンツを読み込むためのmapview idを含むmap.xmlなどの異なるXMLファイルにあります。これは、私と他の人のXMLとの唯一の違いです。

UPDATE:logcat

それはmapView.setBuiltInZoomControls(真)で35行目を指します。 nullpointer例外を使用すると

ありがとうございます。

+0

エラーコードの出力は、貼り付けたコードよりも役に立ちます。クラッシュの原因となった行番号を与える必要があります。 – schwiz

+0

私はlogcatに精通していませんか?それは何ですか? – user701071

+0

私はlogcatをオープンしていますが、コード35のようにnullpointer例外が発生しています。ダブルクリックすると、mapView.setBuiltInZoom(true)が強調表示されます。 – user701071

答えて

1

APIレベル7にダウングレードしましたか?私はAPIレベル8のときにmapView.setBuiltInZoom(true)に問題がありました。APIレベル7に変更したときに例外が停止しました。

関連する問題