Java Question Help figuring out DialogFragment Issue

walterf25

Expert
Licensed User
Longtime User
Hello all, it's been a while since i've posted anything, i was wondering if the experts could help me figure this out.

I'am trying to wrap this library here so far i've gotten pretty much everything working, but i'm getting the error below when trying to open the menu.

I saw this library a very long time ago but i failed miserably to wrap it at that time, i've decided to give it another try and this time i've almost gotten it to work completely, i just need to figure out the error below.

java.lang.NoClassDefFoundError: com.yalantis.contextmenu.lib.MenuAdapter$3
at com.yalantis.contextmenu.lib.MenuAdapter.<init>(MenuAdapter.java:297)
at com.yalantis.contextmenu.lib.ContextMenuDialogFragment.initDropDownMenuAdapter(ContextMenuDialogFragment.java:133)
at com.yalantis.contextmenu.lib.ContextMenuDialogFragment.onCreateView(ContextMenuDialogFragment.java:105)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

below is the java code for the class i'm working with.

B4X:
package com.genesis.contextmenu;

import java.util.ArrayList;
import java.util.List;

import com.yalantis.contextmenu.lib.ContextMenuDialogFragment;
import com.yalantis.contextmenu.lib.MenuObject;
import com.yalantis.contextmenu.lib.MenuParams;
import com.yalantis.contextmenu.lib.interfaces.OnMenuItemClickListener;
import com.yalantis.contextmenu.lib.interfaces.OnMenuItemLongClickListener;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DontInheritEvents;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("ContextMenu")
@Version(1.49f)
@ActivityObject
@Events(values = { "MenuItemClick (item As MenuItem)" })
@DontInheritEvents
@Author(value = "Walter Flores")

public class B4AContextMenu extends AppCompatActivity implements OnMenuItemClickListener, OnMenuItemLongClickListener {
   
    private FragmentManager fragmentManager;
    private ContextMenuDialogFragment mMenuDialogFragment;
    private int actionbarsize;
    private static BA mba;
    private String mEventName;
    public void Initialize(BA ba, String eventname, int actionBarSize){
        mEventName = eventname.toLowerCase(BA.cul);
        actionbarsize = actionBarSize;
        mba = ba;
        fragmentManager = ((AppCompatActivity)mba.activity).getSupportFragmentManager();
        BA.Log("fragment manager: " + fragmentManager.getBackStackEntryCount());
        BA.Log("after fragmentManager");
Toolbar(toolbar.getObject().getContext());//toolbar.getObject();
        initToolbar();
        initMenuFragment();
    }
   
    public void addfragment(BA ba){
        int containerres;
        String container;
        container = "container";
        containerres = BA.applicationContext.getResources().getIdentifier(container, "id", BA.packageName);
        BA.Log("container resource found: " + containerres);
        addFragment(new MainFragment(), true, containerres);
    }
   
   
    private void initMenuFragment() {
        MenuParams menuParams = new MenuParams();
        menuParams.setActionBarSize(actionbarsize);
        menuParams.setMenuObjects(getMenuObjects());
        menuParams.setClosableOutside(false);
        mMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams); 
        mMenuDialogFragment.setItemClickListener(this);
        mMenuDialogFragment.setItemLongClickListener(this);
    }
   
    private List<MenuObject> getMenuObjects() {
        List<MenuObject> menuObjects = new ArrayList<MenuObject>();
        int closemenu;
        String closeicon;
        closeicon = "icn_close";
        closemenu = BA.applicationContext.getResources().getIdentifier(closeicon, "drawable", BA.packageName);
        BA.Log("icon close resource: " + closemenu);
        MenuObject close = new MenuObject();
        close.setResource(closemenu);
        int sendicon;
        String sendstring;
        sendstring = "icn_1";
        sendicon = BA.applicationContext.getResources().getIdentifier(sendstring, "drawable", BA.packageName);
        MenuObject send = new MenuObject("Send Message");
        send.setResource(sendicon);
        int likeicon;
        String likestring;
        likestring = "icn_2";
        likeicon = BA.applicationContext.getResources().getIdentifier(likestring, "drawable", BA.packageName);
        MenuObject like = new MenuObject("Like profile");
        like.setResource(likeicon);
        menuObjects.add(close);
        menuObjects.add(send);
        menuObjects.add(like);
        return menuObjects;
       
    }
   
    private void initToolbar() {
        int toolres;
        String toolbarstring;
        toolbarstring = "toolbar";
        toolres = BA.applicationContext.getResources().getIdentifier(toolbarstring, "id", BA.packageName);
        BA.Log("Toolbar resource found: " + toolres);
        Toolbar mToolbar = (Toolbar)mba.activity.findViewById(toolres);
      
        ((AppCompatActivity)mba.activity).setSupportActionBar(mToolbar);
        if (((AppCompatActivity) mba.activity).getSupportActionBar() != null) {
            ((AppCompatActivity) mba.activity).getSupportActionBar().setHomeButtonEnabled(true);
            ((AppCompatActivity) mba.activity).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            ((AppCompatActivity) mba.activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
        }
        mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
           
            @Override
            public boolean onMenuItemClick(MenuItem arg0) {
                // TODO Auto-generated method stub
                BA.Log("inside onMenuItemClick: " + arg0.toString());
                mba.raiseEventFromUI(this, mEventName + "_menuitemclick", new Object[] {new MenuItemWrapper(arg0)});
                return true;
            }
        });
        //mToolBarTextView.setText("Samantha");
    }
   
    public void OpenMenu(BA ba, MenuWrapper menu1){
        int menu;
        String menuinflate;
        menuinflate = "menu_main";
        menu = BA.applicationContext.getResources().getIdentifier(menuinflate, "menu", BA.packageName);
        BA.Log("menu layout found: " + menu);
        MenuInflater inflater = ((AppCompatActivity)mba.activity).getMenuInflater();
        inflater.inflate(menu, menu1.getObject());
    }
   [/COLOR]
//This is where the app crashes and gives me the error right at this function.
[COLOR=rgb(0, 0, 0)]    public void ShowMenu(BA ba){
        mMenuDialogFragment.show(fragmentManager, "ContextMenuDialogFragment");
    }
   
    protected void addFragment(Fragment fragment, boolean addToBackStack, int containerId) {
        BA.Log("inside addfragment sub");
        ((AppCompatActivity)mba.activity).invalidateOptionsMenu();
        String backStackName = ((AppCompatActivity)mba.activity).getClass().getName()
        BA.Log("fragment Name: " + backStackName);
        boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStackName, 0);
        BA.Log("fragmentPopped: " + fragmentPopped);
        if (!fragmentPopped) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            BA.Log("before adding transaction");
            transaction.add(containerId, fragment, backStackName)
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            if (addToBackStack)
                transaction.addToBackStack(backStackName);
            transaction.commit();
           BA.Log("done executing addFragment");
        }
    }

    @Override
    public void onMenuItemLongClick(View clickedView, int position) {
        // TODO Auto-generated method stub

       
    }

    @Override
    public void onMenuItemClick(View clickedView, int position) {
        // TODO Auto-generated method stub
    BA.Log("item clicked: " + position);   
    }
}

Any help to figure why this is happening will be greatly appreciated, i've never done anything with Fragments, so i'm sort of flying blind here, i'am however glad i've gotten the library to work fine except for when i press on the button to open the menu, then i get this error.

Thanks all
Walter
 

DonManfred

Expert
Licensed User
Longtime User
I saw this library a very long time ago but i failed miserably to wrap it at that time
me too ;)

java.lang.NoClassDefFoundError: com.yalantis.contextmenu.lib.MenuAdapter
You are missing a DependsOn in your code to tell the compiler to use the additional ref. Additionally you need to copy the jar from the dependson to your additional libs folder.
 

walterf25

Expert
Licensed User
Longtime User
You are missing a DependsOn in your code to tell the compiler to use the additional ref. Additionally you need to copy the jar from the dependson to your additional libs folder.

Hi Don, actually i really don't think i needs to add the "DependsOn" since i'am using the source files and not the jar file, other wise when i try to compile i would get all kinds of other errors, as i mentioned on my first post the app compiles just fine,, but it's when i click on the menu button that i get the error i posted on my first post.

I think i'm missing something else, maybe i need to extend the Fragment Activity but as I mentioned i don't have experience working with fragments.

Check the attached image is from the compiled app.

https://www.dropbox.com/s/7xpcyjucxg9ruex/Screenshot_20161203-105405.png?dl=0
 

walterf25

Expert
Licensed User
Longtime User

walterf25

Expert
Licensed User
Longtime User
is the code added to your jar while compiling? I guess no because of the error
Can you upload the generated jar/xml?
Any luck, did you give it a shot, any feedback?
 

DonManfred

Expert
Licensed User
Longtime User
Any luck, did you give it a shot, any feedback?
i´m wondering why the error happens...
In my eyes the classes are in the jar.
I´m not sure what class exactly the error is telling about....
First i thought it would be a missing com.yalantis.contextmenu.lib.MenuAdapter at all... But the class IS inside your jar. So it could not be the problem...
 

walterf25

Expert
Licensed User
Longtime User
i´m wondering why the error happens...
In my eyes the classes are in the jar.
I´m not sure what class exactly the error is telling about....
First i thought it would be a missing com.yalantis.contextmenu.lib.MenuAdapter at all... But the class IS inside your jar. So it could not be the problem...
No worries Don, i figured out the issue, I still need to re-arrange the code and fix some other minor issues but everything works great now, the problem was that I was not including the nineoldandroid.jar file and it is needed to animate the menu opening and closing, anyhow thanks Don, I'll release the library as soon as I have some time to finish it up.

Regards,
Walter
 

DonManfred

Expert
Licensed User
Longtime User
May i ask you to get the source after you finished it up?

I want it just to learn to work with a SupportFragmentManager. I´ll not give it away. That´s the part i have missing knowledge ;)
I have a lot of libs on which i stuck as of exactly this... Want to check if i get one (or even more) of these working
 

walterf25

Expert
Licensed User
Longtime User
May i ask you to get the source after you finished it up?

I want it just to learn to work with a SupportFragmentManager. I´ll not give it away. That´s the part i have missing knowledge ;)
I have a lot of libs on which i stuck as of exactly this... Want to check if i get one (or even more) of these working

I'll upload everything when i get a chance to finish it up, i'am already using it in a project but I still need to clean it up and re-arrange a few things before i can release it.

Cheers,
Walter
 
Top