我的问题是这样的:我正在尝试运行程序代码 soundclouddroid 1.2.2。https://code.google.com/p/soundclouddroid/source/browse/
但是在运行程序时出现错误:
java.lang.RuntimeException: Unable to resume activity {es.manu.sd122.soundCloudDroid/es.manu.sd122.soundCloudDroid.SoundCloudDroid}: java.lang.ClassCastException: android . app.Application
我不明白您为什么会收到此错误,我没有更改 code.google 上提供的代码。
你能帮助我吗?我很绝望。谢谢。
My logcat
10-17 07:29:33.171: I/ActivityThread(327): Pub org.urbanstew.provider.soundclouddroid: es.manu.sd122.soundCloudBase.SoundCloudData
10-17 07:29:33.481: D/AndroidRuntime(327): Shutting down VM
10-17 07:29:33.481: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-17 07:29:33.491: E/AndroidRuntime(327): FATAL EXCEPTION: main
10-17 07:29:33.491: E/AndroidRuntime(327): java.lang.RuntimeException: Unable to resume activity {es.manu.sd122.soundCloudDroid/es.manu.sd122.soundCloudDroid.SoundCloudDroid}: java.lang.ClassCastException: android.app.Application
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.os.Looper.loop(Looper.java:123)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-17 07:29:33.491: E/AndroidRuntime(327): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 07:29:33.491: E/AndroidRuntime(327): at java.lang.reflect.Method.invoke(Method.java:507)
10-17 07:29:33.491: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-17 07:29:33.491: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-17 07:29:33.491: E/AndroidRuntime(327): at dalvik.system.NativeStart.main(Native Method)
10-17 07:29:33.491: E/AndroidRuntime(327): Caused by: java.lang.ClassCastException: android.app.Application
10-17 07:29:33.491: E/AndroidRuntime(327): at es.manu.sd122.soundCloudBase.SoundCloudBaseActivity.getSoundCloudAPI(SoundCloudBaseActivity.java:16)
10-17 07:29:33.491: E/AndroidRuntime(327): at es.manu.sd122.soundCloudBase.SoundCloudMainActivity.updateAuthorizationStatus(SoundCloudMainActivity.java:139)
10-17 07:29:33.491: E/AndroidRuntime(327): at es.manu.sd122.soundCloudBase.SoundCloudMainActivity.onResume(SoundCloudMainActivity.java:91)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.Activity.performResume(Activity.java:3832)
10-17 07:29:33.491: E/AndroidRuntime(327): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
10-17 07:29:33.491: E/AndroidRuntime(327): ... 12 more
10-17 08:28:24.151: I/Process(327): Sending signal. PID: 327 SIG: 9
错误所在的代码:
SoundCloudBaseActivity.java:
package es.manu.sd122.soundCloudBase;
import org.urbanstew.soundcloudapi.SoundCloudAPI;
import android.app.Activity;
public class SoundCloudBaseActivity extends Activity
{
public SoundCloudAPI getSoundCloudAPI()
{
return ((SoundCloudApplicationBase)getApplication()).getSoundCloudAPI();//error line 16
}
public SoundCloudApplicationBase getSCApplicationBase()
{
return (SoundCloudApplicationBase)getApplication();
}
}
SoundCloudMainActivity.java:
public class SoundCloudMainActivity extends SoundCloudBaseActivity implements SoundCloudRequestClient
{
.
.
.
.
public void onResume()
{
super.onResume();
updateAuthorizationStatus();//error line 91
}
.
.
.
.
public void updateAuthorizationStatus()
{
int text;
if(getSoundCloudAPI().getState() == SoundCloudAPI.State.AUTHORIZED)//error linea 139
{
if(mUserName != null)
{
setUserName(mUserName);
return;
}
getSCApplicationBase().processRequest("me", this);
text = R.string.verifying_connection;
}
else
{
text = R.string.please_connect;
}
mAuthorized.setText(text);
}
文件清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.manu.sd122.soundCloudDroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- <provider android:name="es.manu.sd122.soundCloudBase.SoundCloudData" android:authorities="es.manu.sd122.provider.soundclouddroid">
</provider>
-->
<provider android:name="es.manu.sd122.soundCloudBase.SoundCloudData" android:authorities="org.urbanstew.provider.soundclouddroid">
</provider>
<activity
android:name="es.manu.sd122.soundCloudBase.ObtainAccessToken"
android:configChanges="keyboardHidden|orientation"
android:label="Connect with SoundCloud">
</activity>
<activity
android:name="es.manu.sd122.soundCloudBase.ViewTracksActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation"
android:allowTaskReparenting="true" android:label="My Tracks">
</activity>
<service android:name="es.manu.sd122.soundCloudBase.SoundCloudService"></service>
<activity
android:name="es.manu.sd122.soundCloudDroid.SoundCloudDroid"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.UploadActivity"
android:label="Upload File To SoundCloud">
<intent-filter>
<action android:name="android.intent.action.SEND"></action>
<data android:mimeType="audio/*"></data>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="vnd.android.cursor.item/es.manu.sd122.soundCloudDroid.UploadsActivity"></data>
</intent-filter>
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.UploadsActivity"
android:launchMode="singleTop"
android:allowTaskReparenting="true" android:label="View Upload Status">
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.ViewTracksActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation"
android:allowTaskReparenting="true" android:label="My Tracks">
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.ViewOtherTracksActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation"
android:allowTaskReparenting="true" android:label="My Favorites">
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.CustomTrackListsActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation"
android:allowTaskReparenting="true" android:label="Track Lists">
</activity>
<activity
android:name="es.manu.sd122.soundCloudDroid.NewArtistTracksActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation"
android:allowTaskReparenting="true" android:label="Search for Artists">
</activity>
</application>
如果您还需要什么,请随时询问。再次感谢你。