0

I am using Froyo version to run the Application. I got a Fatal Exception when I run the project also the Application has closed unexpectedly. I have 3 Buttons in activity_main.xml file.

Main Activity Code

 public class Main extends Activity {
private DropboxAPI<AndroidAuthSession> mDBApi;
final static String APP_KEY = "707tr8wwfpqrl7z";
final static String APP_SECRET = "mhyp3cxb8eeiyb6";
final static AccessType ACCESS_TYPE = AccessType.APP_FOLDER;

SharedPreferences prefs;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    String dropbox_key = prefs.getString("dropbox_key", "");
    String dropbox_secret = prefs.getString("dropbox_secret", "");


    if (dropbox_key.length() > 0 && dropbox_secret.length() > 0) {
        AccessTokenPair access = new AccessTokenPair(dropbox_key, dropbox_secret);
        AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
        session.setAccessTokenPair(access);
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);
    }

    Button link = (Button) findViewById(R.id.button1);
    Button upload = (Button) findViewById(R.id.button2);
    Button download = (Button) findViewById(R.id.button3);


    link.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
            AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
            if (mDBApi == null) {
                mDBApi = new DropboxAPI<AndroidAuthSession>(session);
            }
            mDBApi.getSession().startAuthentication(Main.this);
        }
    });

    upload.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            File dir = new File(getFilesDir().getAbsolutePath());
            try {
                PrintWriter out = new PrintWriter(new FileWriter(dir + "/test.txt"));
                for (int i = 0; i < 20; i++) {
                    out.println("omg");
                }
                out.close();
                File file = new File(getFilesDir().getAbsolutePath(), "/test.txt");
                FileInputStream in = new FileInputStream(file);
                mDBApi.putFileOverwrite("/test.txt", in, file.length(), null);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (DropboxException e) {
                e.printStackTrace();
            }
        }
    });

    download.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                File output = new File("/mnt/sdcard/test.txt");
                OutputStream out = new FileOutputStream(output);
                mDBApi.getFile("/test.txt", null, out, null);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (DropboxException e) {
                e.printStackTrace();
            }
        }
    });
}


@Override
protected void onResume() {
    super.onResume();
    if (mDBApi != null && mDBApi.getSession().authenticationSuccessful()) {
        try {
            mDBApi.getSession().finishAuthentication();
            AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
            Editor editor = prefs.edit();
            editor.putString("dropbox_key", tokens.key);
            editor.putString("dropbox_secret", tokens.secret);
            editor.commit();
        } catch (IllegalStateException e) {
            Log.i("DbAuthLog", "Error authenticating", e);
        }
    }
  }
}

Manifest code

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dropboxdemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

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

<application 
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity 
        android:name=".Main"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:scheme="db-707tr8wwfpqrl7z" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.dropbox.client2.android.AuthActivity"
        android:configChanges="orientation|keyboard"
        android:launchMode="singleTask" >
        <intent-filter>
            <data android:scheme="db-707tr8wwfpqrl7z" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>
</manifest>

LogCat Error

 08-17 10:47:43.935: E/AndroidRuntime(346): FATAL EXCEPTION: main
 08-17 10:47:43.935: E/AndroidRuntime(346): java.lang.ExceptionInInitializerError
 08-17 10:47:43.935: E/AndroidRuntime(346): atjava.lang.Class.newInstanceImpl(Native Method)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at java.lang.Class.newInstance(Class.java:1409)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 10:47:43.935: E/AndroidRuntime(346):  at android.os.Looper.loop(Looper.java:123)
 08-17 10:47:43.935: E/AndroidRuntime(346):     at android.app.ActivityThread.main(ActivityThread.java:3683)

Any solution to clear this Error ?

Beginner
  • 7
  • 5
Hari
  • 87
  • 9
  • change the minSdkVersion to 8 instead of 10. – mainu Aug 17 '12 at 05:53
  • Still the same error.Applcation has stopped unexpectedly with the same LogCat Error............. – Hari Aug 17 '12 at 05:56
  • see this [link][1].This might be helpful... [1]: http://stackoverflow.com/questions/8585929/java-lang-exceptionininitializererror-caused-by-java-lang-unsatisfiedlinkerror – mainu Aug 17 '12 at 05:59
  • The link describes the about the library issues ............this may be a problem.........but I don't know how to do it............... – Hari Aug 17 '12 at 06:04
  • check your package in your manifest file –  Aug 17 '12 at 07:01
  • The same package I used in the main.java file "com.example.dropboxdemo"............. this is the first LogCat error 08-17 11:54:42.471: E/dalvikvm(346): Could not find class 'com.dropbox.client2.session.AccessTokenPair', referenced from method com.example.dropboxdemo.Main.onCreate.......... please check see this error also – Hari Aug 17 '12 at 07:11

2 Answers2

1

Minsdk version is 10, i.e,gingerbread .

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

You need to set it as 8 for Froyo

 <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
Sunny Kumar Aditya
  • 2,806
  • 4
  • 26
  • 38
  • Still the same error.Applcation has stopped unexpectedly with the same LogCat Error............. – Hari Aug 17 '12 at 05:55
  • I am not that much familiar with the Eclipse. I know How to set the Break Point...but don't know how to use it .... – Hari Aug 17 '12 at 06:25
0

change the minSdkVersion to 8 instead of 10.

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
mainu
  • 625
  • 6
  • 14