2012-08-17 74 views
0

我正在使用Froyo版本來運行應用程序。我得到了一個致命異常當我運行該項目也意外關閉應用程序。我在activity_main.xml文件中有3個按鈕。由於致命異常導致應用程序不能正常工作

主要活動代碼

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 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的錯誤

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) 

不限SOLU要清除此錯誤錯誤

+0

變化,而不是8 10 – mainu 2012-08-17 05:53:49

+0

仍同樣的錯誤。應用程序意外停止與相同的LogCat錯誤............. – Hari 2012-08-17 05:56:05

+0

請參閱此[鏈接] [1]。這可能會有所幫助... [1]:http://stackoverflow.com/questions/8585929/java-lang-exceptionininitializererror-caused-by-java-lang-unsatisfiedlinkerror – mainu 2012-08-17 05:59:31

回答

1

Minsdk版本是10,即薑餅。

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

您需要中的minSdkVersion中的minSdkVersion設置爲8 Froyo的

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="15" /> 
+0

仍然是相同的錯誤。應用程序意外停止機智h相同的LogCat錯誤............. – Hari 2012-08-17 05:55:47

+0

在旁邊放置斷點並找出崩潰 – 2012-08-17 06:19:03

+0

我對Eclipse並不太熟悉。我知道如何設置斷點...但不知道如何使用它... – Hari 2012-08-17 06:25:55

0

更改爲8,而不是10

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