这就是MainActivity
package info.androidhive.slidingmenu;
import info.androidhive.slidingmenu.adapter.NavDrawerListAdapter;
import info.androidhive.slidingmenu.model.NavDrawerItem;
import java.util.ArrayList;
import com.pushbots.push.Pushbots;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends FragmentActivity {
Button contcus;
//private static MediaPlayer play;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
@SuppressWarnings("deprecation")
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
//public String SENDER_ID = "1020197077954";
//public String PUSHBOTS_APPLICATION_ID = "53bd6cf51d0ab1e03f8b4576";
@SuppressWarnings("deprecation")
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Pushbots.init(this,"1020197077954","53bd6cf51d0ab1e03f8b4576");
setContentView(R.layout.activity_main);
contcus = (Button)findViewById(R.id.details1);
GlobalClass.play = MediaPlayer.create(MainActivity.this,R.raw.lovefirstlove);
GlobalClass.play.start();
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// Find People
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
// Photos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// Communities, Will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Pages
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
// What's hot, We will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
//open the camera to send pic to the brid and grom
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(7, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(6, -1)));
// Recycle the typed array
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new HomeFragment();
break;
case 1:
fragment = new FindPeopleFragment();
break;
case 2:
fragment = new PhotosFragment();
break;
case 3:
fragment = new CommunityFragment();
break;
case 4:
fragment = new PagesFragment();
break;
case 5:
fragment = new WhatsHotFragment();
break;
case 6:
fragment = new Cam();
break;
case 7:
fragment = new ReminderFregment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
new AlertDialog.Builder(this).setMessage("מה אתם באמת רוצים לצאת?")
.setPositiveButton("כן", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if(GlobalClass.flag==1)
{
GlobalClass.play.pause();
}
GlobalClass.play.pause();
finish();
System.exit(0);
}
}).setNegativeButton("לא", null).show();
}
return super.onKeyDown(keyCode, event);
}
}
这就是Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.slidingmenu"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<permission android:name="info.androidhive.slidingmenu.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.slidingmenu.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name="info.androidhive.slidingmenu.MyApplication"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application> -->
<application
android:allowBackup="true"
android:icon="@drawable/logohead"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="info.androidhive.slidingmenu.MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ContactMe"
android:label="@string/app_name" />
<activity
android:name=".Facebook_loginActivity"
android:label="@string/app_name" />
<activity
android:name=".ContUsDisplay"
android:label="@string/app_name" />
<activity
android:name=".GlobalClass"
android:label="@string/app_name" />
<activity
android:name=".WillBeActivity"
android:label="@string/app_name" />
<activity
android:name=".RSVPActivity"
android:label="@string/app_name" />
<activity
android:name=".HowManyActivity"
android:label="@string/app_name" />
<activity
android:name=".Sec_dish"
android:label="@string/app_name" />
<activity
android:name=".Desserts"
android:label="@string/app_name" />
<activity
android:name=".Staff"
android:label="@string/app_name" />
<activity
android:name=".ReminderActivity"
android:label="@string/app_name" />
<activity android:name="com.pushbots.push.PBMsg"/>
<activity android:name="com.pushbots.push.PBListener"/>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="info.androidhive.slidingmenu" />
</intent-filter>
</receiver>
<receiver android:name="com.pushbots.push.MsgReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
<service android:name="org.openudid.OpenUDID_service" >
<intent-filter>
<action android:name="org.openudid.GETUDID" />
</intent-filter>
</service>
<meta-data android:value='"@string/facebook_app_id"' android:name='"com.facebook.sdk.ApplicationId"'/>
</application>
</manifest>
这就是我在logcat中遇到的错误:
12-24 11:40:45.756: E/AndroidRuntime(26553): FATAL EXCEPTION: main
12-24 11:40:45.756: E/AndroidRuntime(26553): Process: info.androidhive.slidingmenu, PID: 26553
12-24 11:40:45.756: E/AndroidRuntime(26553): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.slidingmenu/info.androidhive.slidingmenu.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget.Space
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread.access$900(ActivityThread.java:161)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.os.Handler.dispatchMessage(Handler.java:102)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.os.Looper.loop(Looper.java:157)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread.main(ActivityThread.java:5356)
12-24 11:40:45.756: E/AndroidRuntime(26553): at java.lang.reflect.Method.invokeNative(Native Method)
12-24 11:40:45.756: E/AndroidRuntime(26553): at java.lang.reflect.Method.invoke(Method.java:515)
12-24 11:40:45.756: E/AndroidRuntime(26553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
12-24 11:40:45.756: E/AndroidRuntime(26553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
12-24 11:40:45.756: E/AndroidRuntime(26553): at dalvik.system.NativeStart.main(Native Method)
12-24 11:40:45.756: E/AndroidRuntime(26553): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget.Space
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
12-24 11:40:45.756: E/AndroidRuntime(26553): at info.androidhive.slidingmenu.HomeFragment.onCreateView(HomeFragment.java:22)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.Fragment.performCreateView(Fragment.java:1700)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.BackStackRecord.run(BackStackRecord.java:684)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.Activity.performStart(Activity.java:5440)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
12-24 11:40:45.756: E/AndroidRuntime(26553): ... 11 more
12-24 11:40:45.756: E/AndroidRuntime(26553): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Space" on path: DexPathList[[zip file "/data/app/info.androidhive.slidingmenu-3.apk"],nativeLibraryDirectories=[/data/app-lib/info.androidhive.slidingmenu-3, /vendor/lib, /system/lib]]
12-24 11:40:45.756: E/AndroidRuntime(26553): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
12-24 11:40:45.756: E/AndroidRuntime(26553): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-24 11:40:45.756: E/AndroidRuntime(26553): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.createView(LayoutInflater.java:565)
12-24 11:40:45.756: E/AndroidRuntime(26553): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
12-24 11:40:45.756: E/AndroidRuntime(26553): ... 23 more
答案 0 :(得分:0)
替换这些行:
import android.app.Fragment;
import android.app.FragmentManager;
使用:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
编辑:
改变这个:
FragmentManager fragmentManager = getFragmentManager();
为:
FragmentManager fragmentManager = getSupportFragmentManager();
在所有碎片中替换它:
import android.app.Fragment;
使用:
import android.support.v4.app.Fragment;
答案 1 :(得分:0)
崩溃日志(cat)的这一部分表示在运行时找不到类android.support.v7.widget.Space
。
12-24 11:40:45.756: E/AndroidRuntime(26553): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget.Space
......
12-24 11:40:45.756: E/AndroidRuntime(26553): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Space" on path: DexPathList[[zip file "/data/app/info.androidhive.slidingmenu-3.apk"],nativeLibraryDirectories=[/data/app-lib/info.androidhive.slidingmenu-3, /vendor/lib, /system/lib]]
要修复它,请确保您的libs文件夹中有最新支持v7 appcompat库或构建依赖项(gradle)。