Activity不会运行并一起停止应用程序

时间:2014-11-30 13:24:55

标签: android

我最近在我的应用程序中添加了一个滑动菜单,我按照在线提到的说明进行操作,但由于我是Android界的新手,我似乎没有得到错误并且知道如何修复它

活动是degree_programs活动

package com.noura.luba;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.TypedArray;  
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;  
import android.widget.ListView;

public class Degree_programs extends Activity { 
String[] menutitles;  TypedArray menuIcons;
 // nav drawer title
 private CharSequence mDrawerTitle;
 private CharSequence mTitle;
  private DrawerLayout mDrawerLayout;
 private ListView mDrawerList;   
private ActionBarDrawerToggle mDrawerToggle;
  private List<RowItem> rowItems;
 private CustomAdapter adapter;

 @SuppressLint("NewApi")
 @Override  protected void onCreate(Bundle savedInstanceState) {

       setContentView(R.layout.sliding_menu);

       mTitle = mDrawerTitle = getTitle();
       menutitles = getResources().getStringArray(R.array.titles);
       menuIcons = getResources().obtainTypedArray(R.array.icons);    
       mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
       mDrawerList = (ListView) findViewById(R.id.slider_list); 

         rowItems = new ArrayList<RowItem>(); 

         for (int i = 0; i < menutitles.length; i++) { 
           RowItem items = new RowItem(menutitles[i], menuIcons.getResourceId(      i, -1)); 
           rowItems.add(items);
     }    

   menuIcons.recycle();    
   adapter = new CustomAdapter(getApplicationContext(), rowItems);   
   mDrawerList.setAdapter(adapter); 
   mDrawerList.setOnItemClickListener(new SlideitemListener()); 

 // enabling action bar app icon and behaving it as toggle button                                                       
    getActionBar().setDisplayHomeAsUpEnabled(true);     getActionBar().setHomeButtonEnabled(true);

  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,     R.drawable.admission, R.string.app_name,R.string.app_name)
{       
        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 
           updateDisplay(0); 
      }
    }  class SlideitemListener implements ListView.OnItemClickListener { 

        @Override  
          public void onItemClick(AdapterView<?> parent, View view, int position, long id)   
             {                  updateDisplay(position); 
                 } 

       }  private void updateDisplay(int position) { 
                Fragment fragment = null;  
                 switch (position) {       
                         case 0:      fragment = new FB_Fragment();               
                                             break;  
                         case 1:       fragment = new FB_Fragment();    
                                            break;   
                         case 2:         fragment = new FB_Fragment();            
                                              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    
                     setTitle(menutitles[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); 
  } 
  @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.settings:
        Intent intentSettings = new Intent(getApplicationContext(), Settings.class);
        startActivity(intentSettings);
         return true;    */

    case R.id.information:
       final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.information);
        return true;

     case R.id.logOut:

         Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
         return true;

    case R.id.email:

         Intent i = new Intent(Intent.ACTION_SEND);
         i.setType("*/*");
   /*      i.putExtra(Intent.EXTRA_EMAIL, new String[] {
             ANDROID_SUPPORT_EMAIL
         }); */
         i.putExtra(Intent.EXTRA_SUBJECT, "Crash report");
         i.putExtra(Intent.EXTRA_TEXT, "Some crash report details");

         startActivity(createEmailOnlyChooserIntent(i, "Send via email"));
        return true;

      default:
        return super.onOptionsItemSelected(item);
}
}

public Intent createEmailOnlyChooserIntent(Intent source,
        CharSequence chooserTitle) {
        Stack<Intent> intents = new Stack<Intent>();
        Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                "noura.h.hadi@gmail.com", null));
        List<ResolveInfo> activities = getPackageManager()
                .queryIntentActivities(i, 0);

        for(ResolveInfo ri : activities) {
            Intent target = new Intent(source);
            target.setPackage(ri.activityInfo.packageName);
            intents.add(target);
        }

        if(!intents.isEmpty()) {
            Intent chooserIntent = Intent.createChooser(intents.remove(0),
                    chooserTitle);
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    intents.toArray(new Parcelable[intents.size()]));

            return chooserIntent;
        } else {
            return Intent.createChooser(source, chooserTitle);
        }
    }


 /***   * 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.email).setVisible(!drawerOpen);           
   return super.onPrepareOptionsMenu(menu); 
    }

  /**   * 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 toggles 
          mDrawerToggle.onConfigurationChanged(newConfig); 
  }
 }

滑动菜单:

<android.support.v4.widget.DrawerLayout      
xmlns:android="http://schemas.android.com/apk/res/android"      
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
   <!-- The main content view -->            
<FrameLayout                  
android:id="@+id/frame_container"        
  android:layout_width="match_parent"        
  android:layout_height="match_parent" />    
 <!-- The navigation drawer list --> 
  <ListView     
android:id="@+id/slider_list"      
 android:layout_width="240dp"       
android:layout_height="match_parent"     
  android:layout_gravity="start"     
  android:background="#ffffff"      
 android:choiceMode="singleChoice"     
  android:divider="@android:color/transparent"    
   android:dividerHeight="0dp" />
 </android.support.v4.widget.DrawerLayout>

这是logcat

    11-30 19:03:10.264: E/AndroidRuntime(579): FATAL EXCEPTION: main
11-30 19:03:10.264: E/AndroidRuntime(579): java.lang.NoSuchMethodError: com.noura.luba.Sliding_menu.getActionBar
11-30 19:03:10.264: E/AndroidRuntime(579):  at com.noura.luba.Sliding_menu.onCreate(Sliding_menu.java:64)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.os.Looper.loop(Looper.java:123)
11-30 19:03:10.264: E/AndroidRuntime(579):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-30 19:03:10.264: E/AndroidRuntime(579):  at java.lang.reflect.Method.invokeNative(Native Method)
11-30 19:03:10.264: E/AndroidRuntime(579):  at java.lang.reflect.Method.invoke(Method.java:507)
11-30 19:03:10.264: E/AndroidRuntime(579):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-30 19:03:10.264: E/AndroidRuntime(579):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-30 19:03:10.264: E/AndroidRuntime(579):  at dalvik.system.NativeStart.main(Native Method)
11-30 19:03:12.432: I/Process(579): Sending signal. PID: 579 SIG: 9

有什么建议吗?

0 个答案:

没有答案