2013-04-25 61 views
0

我试图设置一个允许用户查找本地企业和活动的应用程序。我有一个工作地图,但是我无法将它集成到选项卡式操作栏中。不幸的是它说:“不幸的是,[app]已经停止。” 任何帮助将不胜感激。将操作栏与Google Maps API v2集成

ActionBarMain.java

@SuppressLint("NewApi") 
public class ActionBarMain extends Activity implements TabListener { 
    RelativeLayout rl; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_action_bar_main); 
     try { 
      rl = (RelativeLayout) findViewById(R.id.mainLayout); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      ActionBar bar = getActionBar(); 
      bar.addTab(bar.newTab().setText("Map").setTabListener(this)); 
      bar.addTab(bar.newTab().setText("Businesses").setTabListener(this)); 
      bar.addTab(bar.newTab().setText("Events").setTabListener(this)); 
      bar.addTab(bar.newTab().setText("Facebook").setTabListener(this)); 

      bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM 
        | ActionBar.DISPLAY_USE_LOGO); 
      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
      bar.setDisplayShowHomeEnabled(true); 
      bar.setDisplayShowTitleEnabled(false); 
      bar.show(); 

     } catch (Exception e) { 
      e.getMessage(); 
     } 
     /** 
     * Hiding Action Bar 
     */ 
    } 

    Fragment fram1; 
    FragmentTransaction fragMentTra = null; 
    FragMent2 fram2; 
    FragMent3 fram3; 
    FragMent4 fram4; 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_action_bar_main, menu); 
     return true; 
    } 

    @Override 
    public void onTabReselected(Tab tab, FragmentTransaction ft) { 
    } 

    @Override 
    public void onTabSelected(Tab tab, FragmentTransaction ft) { 

     if (tab.getText().equals("Map")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram1 = new Fragment(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram1); 
      fragMentTra.commit(); 
     } else if (tab.getText().equals("Businesses")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram2 = new FragMent2(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram2); 
      fragMentTra.commit(); 
     } else if (tab.getText().equals("Events")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram3 = new FragMent3(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram3); 
      fragMentTra.commit(); 
     } else if (tab.getText().equals("Facebook")) { 
      try { 
       rl.removeAllViews(); 
      } catch (Exception e) { 
      } 
      fram2 = new FragMent2(); 
      fragMentTra.addToBackStack(null); 
      fragMentTra = getFragmentManager().beginTransaction(); 
      fragMentTra.add(rl.getId(), fram2); 
      fragMentTra.commit(); 
     } 

    } 

    @Override 
    public void onTabUnselected(Tab tab, FragmentTransaction ft) { 

    } 

} 

FragMent1.java:

public class FragMent1 extends FragmentActivity{ 

SupportMapFragment mMap; 
GoogleMap googleMap; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_action_bar_main); 

     mMap = (SupportMapFragment) getSupportFragmentManager() 
     .findFragmentById(R.id.mainGrid); 

     googleMap = mMap.getMap(); 
} 
} 

的AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.ahmad.actionBar" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <permission 
     android:name="com.ahmad.actionbar.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature"/> 
    <uses-permission android:name="com.ahmad.actionbar.permission.MAPS_RECEIVE"/> 

    <uses-sdk 
     android:minSdkVersion="11" 
     android:targetSdkVersion="17" /> 

    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <!-- The following two permissions are not required to use 
    Google Maps Android API v2, but are recommended. --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <!-- Maps API needs OpenGL ES 2.0. --> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:allowBackup="True"> 
     <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="super_secret_key"/> 
     <activity 
      android:name="com.ahmad.actionbar.MainActivity" 
      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=".ActionBarMain" 
      android:label="@string/title_activity_action_bar_main" 
      android:uiOptions="splitActionBarWhenNarrow" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

编辑:

固定试图INTEG一些错误评价两个应用程序并添加新的logcat。

的logcat:

04-24 21:34:33.242: D/AndroidRuntime(11335): Shutting down VM 
04-24 21:34:33.242: W/dalvikvm(11335): threadid=1: thread exiting with uncaught exception (group=0x40e26930) 
04-24 21:34:33.252: E/AndroidRuntime(11335): FATAL EXCEPTION: main 
04-24 21:34:33.252: E/AndroidRuntime(11335): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmad.actionBar/com.ahmad.actionbar.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ahmad.actionbar.MainActivity" on path: /data/app/com.ahmad.actionBar-2.apk 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread.access$600(ActivityThread.java:141) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.os.Looper.loop(Looper.java:137) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread.main(ActivityThread.java:5041) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at java.lang.reflect.Method.invokeNative(Native Method) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at java.lang.reflect.Method.invoke(Method.java:511) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at dalvik.system.NativeStart.main(Native Method) 
04-24 21:34:33.252: E/AndroidRuntime(11335): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ahmad.actionbar.MainActivity" on path: /data/app/com.ahmad.actionBar-2.apk 
04-24 21:34:33.252: E/AndroidRuntime(11335): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.Instrumentation.newActivity(Instrumentation.java:1054) 
04-24 21:34:33.252: E/AndroidRuntime(11335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) 
04-24 21:34:33.252: E/AndroidRuntime(11335): ... 11 more 

回答

0

错误说 “找不到类MainActivity”。

您发布的类名为ActionBarMain,而您的Manifest文件表示MainActivity是您的主类。

如果您的项目中没有任何MainActivity,并且您希望ActionBarMain成为您的第一个活动。然后在清单文件中用MainAcitivty替换ActionBarMain。

+0

谢谢。我从一张工作地图和一个工作选项卡式动作栏开始。只是将它们结合在一起的错误。 – 2013-04-25 21:00:58

+0

它是如何解决问题的? – Sharj 2013-04-26 08:42:50

+0

这不是最后一个问题,但我能够解决它的其余问题,现在就开始运行。再次感谢。 – 2013-04-28 06:17:26