0

I've recently added a sliding menu to my application, I followed the instructions as mentioned online but since I'm new to the android world I don't seem to get the error and know how to fix it

The activity is the degree_programs activity

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); 
  }
 }

The sliding menu :

<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>

This is the 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

Any suggestions?

DevSe
  • 53
  • 3
  • 11
  • Noura ya Noura, if you added android-support-v4 jar to the project using class path, then you have to go to the export tab (next to library tab) and select the jar file to be exported with the apk, using the checkbox next to it – Yazan Nov 30 '14 at 14:49
  • @Yazan i've intentionally unchecked the private libraries box because of this error : [2014-11-30 16:57:18 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/annotation/AnimRes; [2014-11-30 16:57:18 - LUBA] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/annotation/AnimRes; – DevSe Nov 30 '14 at 14:58
  • well, i would rather find a sol for that error, because the jar files should be exported with the APK, so you might have a conflict, by adding same support jar file in class path and /lib folder, or even two different versions, so you have to fix that error. – Yazan Nov 30 '14 at 15:04
  • @Yazan so you mean that the code has no errors in it and all i should focus on is the jar file error? – DevSe Nov 30 '14 at 15:20
  • yes i think the error `Unable to execute dex: Multiple dex files define` is the root cause of the problem, if you solve it you will have it working, because unchecking export jar is not a true sol, also i saw the other note about `android.process.acore has stopped unexspectedly` has nothing to do with your app as it's a different package name, which means a differnt app, as your apps package name is `com.noura.luba` i think `android.process.acore` is a system app you have nothing to do with – Yazan Nov 30 '14 at 15:31
  • @yazan i'll go through the jar files to solve the issue... but concerning the android.process.acore does that mean i can't get rid of it? it's pretty annoying and keeps on showing up – DevSe Nov 30 '14 at 15:37
  • it's another app you have nothing to do with, it's something in the device or the emulator you are using, i am not sure what to do with, it needs some search to find out. if you are using emulator try to create another one and use it... maybe – Yazan Nov 30 '14 at 15:42
  • @Yazan the problem was resolved after creating a new emulator... but the application is giving me an error concerning the getActionBar method. i'll include the new logCat in the question – DevSe Nov 30 '14 at 17:27
  • check this http://stackoverflow.com/questions/12977819/nosuchmethoderror-error-for-getactionbar-api-8 – Yazan Dec 01 '14 at 07:26

0 Answers0