我的问题是:我正在尝试运行程序代码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>
如果您还有其他需要,请随时提出。再次感谢你。
答案 0 :(得分:5)
如果您已创建自定义应用程序类型,则需要在清单中指定它:
<application
android:name="es.manu.sd122.soundCloudBase.SoundCloudApplicationBase"
希望这会有所帮助:)
答案 1 :(得分:0)
我想,在这里你需要返回SoundCloudAPI
个对象,但是你要返回SoundCloudApplicationBase
,
public SoundCloudAPI getSoundCloudAPI()
{
return ((SoundCloudApplicationBase)getApplication()).getSoundCloudAPI();//error line 16
}
所以试着这样做,
public SoundCloudAPI getSoundCloudAPI()
{
return ((SoundCloudAPI)getApplication()).getSoundCloudAPI();//error line 16
}
答案 2 :(得分:0)
您已发布SoundCloud 库项目的清单代码,建议您尝试直接运行该代码。这不是它的工作方式。
相反,请查看SoundCloudBase
和SoundCloudDroid
,并确保前者设置为 Android图书馆计划,并且后者有对它的引用。之后,运行SoundCloudDroid
。正如您在该项目的清单中所看到的,它正确地声明了应用程序'name'属性,该属性是在运行时实例化的扩展Application
的类:
android:name="SoundCloudApplication"
如果您不知道如何将SoundCloudBase
设置为Android图书馆计划,请查看此处:
编辑:看起来我的初始陈述不完全正确,因为清单不是SoundCloudBase
中包含的清单。但是,它缺少应用程序名称属性,这是引发异常的直接原因。您需要更改的所有内容都不是添加该属性并确保它指向正确的位置(例如,如果您不确定,请使用完全限定的路径名称)。
答案 3 :(得分:-1)
无法通过类型转换将应用程序类转换为其他类型。