Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Creating an Account and App on Parse.com

Arthur Podkowiak
Arthur Podkowiak
3,633 Points

Unexpected Top Level Exception using Parse

I know there is a question like this, but it did not help me, I still have problems with my app.

I am using Android Studio to build the self destructing message app and have run into problems getting Parse to run. I followed the instructions on the Parse website and nothing has been resolved. This is what my code looks like:

Ribbit Application:

package artattack.ribbit;

import android.app.Application;

import com.parse.Parse;
import com.parse.ParseObject;

/**
 * Created by Arthur on 5/18/2015.
 */
public class RibbitApplication extends Application {

    @Override
    public void onCreate() {

        super.onCreate();
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "XHZY8w6SKagXirLzbJSLP4i7DQlqwrGIMeJQoHsN", "OJGeajhjfgOmuKTv5RA379HBOkYpZBcD3WZ3ALLe");

        ParseObject testObject = new ParseObject("TestObject");
        testObject.put("foo", "bar");
        testObject.saveInBackground();
    }
}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="artattack.ribbit" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name=".RibbitApplication">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".SignUpActivity"
            android:label="@string/title_activity_sign_up"
            android:screenOrientation="portrait"
            android:parentActivityName="artattack.ribbit.LoginActivity">
        </activity>
    </application>

</manifest>

Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "artattack.ribbit"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}

And my libs folder has the following files in it, which are the .jar files taken from the SDK downloadable today:

bolts-android-1.2.0.jar
bolts-android-1.2.0-javadoc.jar
Parse-1.9.2.jar
ParseFacebookUtilsV3-1.9.2.jar
ParseFacebookUtilsV4-1.9.2.jar

PLEASE HELP!!!

These are the errors showing up:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\Arthur\AppData\Local\Android\sdk2\build-tools\22.0.1\dx.bat --dex --no-optimize --output C:\Users\Arthur\AndroidStudioProjects\Ribbit\app\build\intermediates\dex\debug --input-list=C:\Users\Arthur\AndroidStudioProjects\Ribbit\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/parse/FacebookAuthenticationProvider$1;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)

1 Answer

Hello,

Could you remove the file ParseFacebookUtilsV3-1.9.2.jar from your libs directory? You have two versions of the same lib being loaded and I'm assuming you want the newest version. Let me know if this helps or not and we can try further troubleshooting methods.

Arthur Podkowiak
Arthur Podkowiak
3,633 Points

Dawg....that worked. Now why is it that it worked though? Because I didn't compile those specific libraries, did I?

A simple explaination is that there were two versions of the same library(so we got rid of the older version). I believe what ended up happening was that there then became two entires for the same methods which was causing the exceptions.

The moral is, however, that multiple versions of the same library is not a good thing.

I'm not sure why Parse includes both in their download when it is likely to cause problems like this.