我刚开始使用谷歌的admob,我决定先做一个Hello World应用程序,然后再把它和我的主应用程序结合起来。因此,我只包括了这里所写的依赖项,并编译了应用程序,但这个错误在日志猫中弹出,我的应用程序崩溃了:“(
09-06 20:21:07.946 10254 10254 E AndroidRuntime FATAL EXCEPTION: main
09-06 20:21:07.946 10254 10254 E AndroidRuntime Process: com.dame.dane, PID: 10254
09-06 20:21:07.946 10254 10254 E AndroidRuntime java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dame.dane/com.dame.dane.MainActivity}: java.lang.ClassCastException: com.dame.dane.MainActivity cannot be cast to com.tapjoy.TJPlacementListener
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3093)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:106)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.os.Looper.loop(Looper.java:193)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:6865)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
09-06 20:21:07.946 10254 10254 E AndroidRuntime Caused by: java.lang.ClassCastException: com.dame.dane.MainActivity cannot be cast to com.tapjoy.TJPlacementListener
09-06 20:21:07.946 10254 10254 E AndroidRuntime at com.dame.dane.MainActivity.onCreate(MainActivity.java:35)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.Activity.performCreate(Activity.java:8606)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.Activity.performCreate(Activity.java:8597)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1289)
09-06 20:21:07.946 10254 10254 E AndroidRuntime at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2923)
09-06 20:21:07.946 10254 10254 E AndroidRuntime ... 11 more
09-06 20:30:00.338 11818 11818 I com.dame.dane Late-enabling -Xcheck:jni
09-06 20:30:00.537 11818 11818 I com.dame.dane The ClassLoaderContext is a special shared library.
09-06 20:30:00.802 11818 11818 D OpenGLRenderer Skia GL Pipeline
09-06 20:30:00.920 11818 11818 W com.dame.dane Class com.tapjoy.internal.hk failed lock verification and will run slower.
09-06 20:30:00.920 11818 11818 W com.dame.dane Common causes for lock verification issues are non-optimized dex code
09-06 20:30:00.920 11818 11818 W com.dame.dane and incorrect proguard optimizations.
09-06 20:30:00.922 11818 11818 W com.dame.dane Class com.tapjoy.internal.fz failed lock verification and will run slower.
09-06 20:30:00.934 11818 11818 W com.dame.dane Class com.tapjoy.internal.gz failed lock verification and will run slower.
09-06 20:30:00.935 11818 11818 W com.dame.dane Class com.tapjoy.internal.hh failed lock verification and will run slower.
09-06 20:30:00.936 11818 11818 I Tapjoy The debug mode has been enabled
09-06 20:30:00.948 11818 11818 W com.dame.dane Class com.tapjoy.FiveRocksIntegration failed lock verification and will run slower.
09-06 20:30:00.951 11818 11818 W com.dame.dane Class com.tapjoy.FiveRocksIntegration$1 failed lock verification and will run slower.
09-06 20:30:00.984 11818 11818 W com.dame.dane Class com.tapjoy.internal.hc failed lock verification and will run slower.
09-06 20:30:01.030 11818 11818 W com.dame.dane Class com.tapjoy.internal.b failed lock verification and will run slower.
09-06 20:30:01.036 11818 11818 W com.dame.dane Class com.tapjoy.internal.gx failed lock verification and will run slower.
09-06 20:30:01.038 11818 11818 W com.dame.dane Class com.tapjoy.internal.hl failed lock verification and will run slower.
09-06 20:30:01.065 11818 11818 W com.dame.dane Class com.tapjoy.internal.gy failed lock verification and will run slower.
09-06 20:30:01.066 11818 11818 W com.dame.dane Class com.tapjoy.internal.hm$1 failed lock verification and will run slower.
09-06 20:30:01.071 11818 11818 W com.dame.dane Class com.tapjoy.internal.ht failed lock verification and will run slower.
09-06 20:30:01.086 11818 11818 E com.dame.dane Invalid ID 0x00000000.
09-06 20:30:01.093 11818 11818 W com.dame.dane Class com.tapjoy.TJContentActivity failed lock verification and will run slower.
09-06 20:30:01.132 11818 11818 I TapjoyLog TapjoyConnect: Connect Flags:
09-06 20:30:01.132 11818 11818 I TapjoyLog TapjoyConnect: --------------------
09-06 20:30:01.132 11818 11818 I TapjoyLog TapjoyConnect: key: TJC_OPTION_PLACEMENT_SERVICE_URL, value: https%3A%2F%2Fplacements.tapjoy.com%2F
09-06 20:30:01.133 11818 11818 I TapjoyLog TapjoyConnect: key: TJC_OPTION_SERVICE_URL, value: https%3A%2F%2Fws.tapjoyads.com%2F
09-06 20:30:01.133 11818 11818 I TapjoyLog TapjoyConnect: hostURL: [https://ws.tapjoyads.com/]
09-06 20:30:01.133 11818 11818 I TapjoyLog TapjoyConnect: redirectDomain: [ws.tapjoyads.com]
09-06 20:30:01.133 11818 11818 I TapjoyLog TapjoyConnect: --------------------
09-06 20:30:01.136 11818 11849 I TapjoyLog TapjoyGpsHelper: Looking for Google Play Services...
09-06 20:30:01.136 11818 11849 I TapjoyLog TapjoyGpsHelper: Packaged Google Play Services found, fetching advertisingID...
09-06 20:30:01.137 11818 11849 I TapjoyLog TapjoyGpsHelper: Packaged Google Play Services version: 8298000
09-06 20:30:01.137 11818 11818 W com.dame.dane Class com.tapjoy.internal.fl failed lock verification and will run slower.
09-06 20:30:01.138 11818 11818 I Tapjoy New session started
```java
I know that TapJoy is another ad resource but i cant figure out why is this happening. I also include my short and fresh xml, mainactivity and gradle
package com.Dame.Dane;
import android.app.*;
import android.os.*;
public class MainActivity extends Activity
{
//app id=ca-app-pub-5290457881705727~8592165721
//ad unit-id=ca-app-pub-5290457881705727/5712503908
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.Dame.Dane"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.gms:play-services-ads:19.3.0'
}
请帮助,我甚至无法编译他们给的演示应用程序。
我的错!正如这里所写的,你必须初始化你的应用程序id到清单,否则你会得到一些错误,它工作了!