0
votes

Currently, I am developing an android app using PhotoEditor library. I have followed the Getting Started and Setting up the View sections as explained on the page. However, somehow, I cannot inflate the UI XML that contains PhotoEditorView. Here is my code:

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

        <ja.burhanrashid52.photoeditor.PhotoEditorView
            android:id="@+id/photoEditorView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ja.burhanrashid52.photoeditor.PhotoEditorView>

</RelativeLayout>

Fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    try {
        final View view = inflater.inflate(R.layout.app_fragment_edit_picture, container, false);
    }
    catch (Exception e) {
        LogHelper.LogError("TEST");
    }

    return null;
}

I put the try-catch and return null there only for testing.

Error:

Binary XML file line #9: Binary XML file line #9: Error inflating class ja.burhanrashid52.photoeditor.PhotoEditorView

Does anyone have a clue?

As requested, here is the full stack trace:

android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class ja.burhanrashid52.photoeditor.PhotoEditorView at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at com.mobileop.app.gui.fragments.EditPictureFragment.onCreateView(EditPictureFragment.java:54) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2466) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5551) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class ja.burhanrashid52.photoeditor.PhotoEditorView at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) ... 30 more Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at android.view.LayoutInflater.createView(LayoutInflater.java:619) ... 35 more Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lja/burhanrashid52/photoeditor/R$styleable; at ja.burhanrashid52.photoeditor.PhotoEditorView.init(PhotoEditorView.java:72) at ja.burhanrashid52.photoeditor.PhotoEditorView.(PhotoEditorView.java:48) ... 37 more Caused by: java.lang.ClassNotFoundException: Didn't find class "ja.burhanrashid52.photoeditor.R$styleable" on path: DexPathList[[zip file "/data/app/com.mobileop-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mobileop-1/lib/arm, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) ... 39 more Suppressed: java.lang.ClassNotFoundException: ja.burhanrashid52.photoeditor.R$styleable at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 40 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

2
have you put that on your app-level build.gradle file: implementation 'ja.burhanrashid52:photoeditor:0.4.0' clean/build and retrySebastienRieu
What is your full stack trace for this error?Marco Batista
@SebastienRieu I have put it like this: implementation files('libs/photoeditor-0.4.0.jar'). I name the library photoeditor-0.4.0.jar. Previously, I have tried implementation 'ja.burhanrashid52:photoeditor:0.4.0', but it result an error Manifest merger failed with multiple errors, see logsYusril Maulidan Raji
have you retry to add the dependency normally ? if it doesn't work could you put you all manifest error stacktrace ?SebastienRieu
@MarcoBatista I have added the full stack trace on the question as requested. (y)Yusril Maulidan Raji

2 Answers

1
votes

You have to return a View, you are returning null in the function.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle 
savedInstanceState) {
// Inflate the layout for this fragment
try {
    final View view = inflater.inflate(R.layout.app_fragment_edit_picture, container, 
false);
}
catch (Exception e) {
    LogHelper.LogError("TEST");
}

return view;
}
1
votes

Update

Whole Code with Main,fragment xmls and classes.

MainActivity XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragmentContainer"/>

</LinearLayout>

MainActivity Java

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;


public class PhotoEditorActivity extends AppCompatActivity {
FragmentManager fragManager;
FragmentTransaction fragTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_editor);

    fragManager=getFragmentManager();
    fragManager.findFragmentById(R.id.fragmentContainer);
    fragTransaction=fragManager.beginTransaction();
    fragTransaction.replace(R.id.fragmentContainer, new PhotoEditorFragment());
    fragTransaction.commit();

}
}

Fragment XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">

<ja.burhanrashid52.photoeditor.PhotoEditorView
    android:id="@+id/photoEditorView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</ja.burhanrashid52.photoeditor.PhotoEditorView>

</RelativeLayout>

Fragment Java

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PhotoEditorFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle 
savedInstanceState) {
    View itemView=inflater.inflate(R.layout.photo_editor_fragment,container,false);
    try
    {
        return itemView;}
    catch (Exception e){
        return null;
    }

}
}

This code runs fine on my android studio. I have not imported the jar but added the dependency in gradle

dependencies {
    implementation 'ja.burhanrashid52:photoeditor:0.4.0'
}