Using the Outpan JAVA API

I am having problems using the Outpan JAVA API in my android project. This API is also mentioned on the official Outpan website.

My progress so far is:

  • I downloaded the Outpan JAVA APIs from here and extracted them.
  • I copied the io folder inside the src folder (inside the downloaded folder) to home -> AndroidStudioProjects -> (My project name) -> app-> src-> main-> java (I am using Android Studio on ubuntu) .
  • I copied the .jar file inside the libs folder (inside the downloaded folder) to home-> AndroidStudioProjects -> (My project name) -> app-> libs folder.
  • I opened my android studio project that was created earlier (it scans barcodes using zxing library) and added these 2 lines to my import statements in the project: import io.github.johncipponeri.outpanapi.OutpanAPI; import io.github.johncipponeri.outpanapi.OutpanObject;
  • Then I used the usual commands that were listed in the github repository (which I mentioned earlier) as well as the corresponding API key (I am already registered with Outpan).
  • Then I went to the gradle file (Module: app) of my project and added this line to the "Depedencies" section: compile files ('libs / org.json-20131017.jar')

So when I tried to debug the application on my phone the following errors appeared -:

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidEmbedded201Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidIntegration201Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidLegacy201Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
/home/ashutoshsaboo/AndroidStudioProjects/CodeScan/app/src/main/java/io/github/johncipponeri/outpanapi/OutpanAPI.java
Error:(33, 51) error: cannot find symbol method getEncoder()
/home/ashutoshsaboo/AndroidStudioProjects/CodeScan/app/src/main/java/io/github/johncipponeri/outpanapi/OutpanObject.java
Error:(44, 31) error: cannot find symbol method getNames(JSONObject)
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 4.348 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console

      

It would be better if you download the API yourself from GitHub, as you will be able to view all files individually, because I cannot paste the code of all .java files here.

Edit:

Thanks @JohnCipponeri for your help. I downloaded the new updated version of your API and put the folder in the src folder in the app-> src-> main-> java folder and the .jar file in the libs folder in the app-> libs folder. Also, I put "outpan-api-java-1.1.jar" in my app-> libs folder and added the following lines to my gradle file under dependencies:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/outpan-api-java-1.1.jar')
compile 'com.android.support:appcompat-v7:22.2.0'

      

But, unfortunately, the two previous errors have not been resolved. So my Android package name should have the same name as " io.github.johncipponeri.outpanapi " because my package name is different at the moment.

My updated message dialog is:

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidEmbedded201Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidIntegration201Library UP-TO-DATE
:app:prepareComJourneyappsZxingAndroidLegacy201Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
/home/ashutoshsaboo/AndroidStudioProjects/CodeScan/app/src/main/java/io/github/johncipponeri/outpanapi/OutpanAPI.java
Error:(48, 17) error: unreported exception JSONException; must be caught or declared to be thrown
/home/ashutoshsaboo/AndroidStudioProjects/CodeScan/app/src/main/java/io/github/johncipponeri/outpanapi/OutpanObject.java
Error:(44, 31) error: cannot find symbol method getNames(JSONObject)
Note: /home/ashutoshsaboo/AndroidStudioProjects/CodeScan/app/src/main/java/com/ashutoshsaboo/codescan/MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 28.092 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console

      

The error in this part of OutpanObject.java is:

public OutpanObject(JSONObject json) {
        this();

        this.gtin = json.getString("gtin");
        this.outpan_url = json.getString("outpan_url");

        if (!json.isNull("name"))
            this.name = json.getString("name");

        if (!json.isNull("attributes")) {
            JSONObject attrObject = json.getJSONObject("attributes");
            String[] attrs = JSONObject.getNames(attrObject);

            for (int a = 0; a < attrs.length; a++)
                this.attributes.put(attrs[a], attrObject.getString(attrs[a]));
        }

        if (!json.isNull("images")) {
            JSONArray imgs = json.getJSONArray("images");
            for (int i = 0; i < imgs.length(); i++)
                this.images.add(imgs.getString(i));
        }

        if (!json.isNull("videos")) {
            JSONArray vids = json.getJSONArray("videos");
            for (int i = 0; i < vids.length(); i++)
                this.videos.add(vids.getString(i));
        }
    }

      

Another error in this part of OutpanAPI.java is:

while ((numCharsRead = isr.read(charArray)) > 0)
                sb.append(charArray, 0, numCharsRead);

            jsonResult = new JSONObject(sb.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

      

+3


source to share


1 answer


I am the one who created the Java wrapper for the Outpan API.

I faced the same problem. Android only supports Java 1.7, and the JAR version you are using was compiled using Java 1.8 and 1.8 Base64.

If you download the latest JAR from https://github.com/johncipponeri/outpan-api-java/releases/tag/v1.1 this issue will be resolved.

Hope it helps.



Edit :

You can follow the instructions below to make it work. https://github.com/johncipponeri/outpan-api-java/blob/master/README.md#using-with-android-studio

You don't need to include your own copy org.json-20131017.jar

as it is wrapped in.

+2


source







All Articles