我在我的应用程序中使用了一个adMob横幅,但是当我运行它时,我收到的错误如下:
12-17 12:32:19.098: E/Trace(1244): error opening trace file: No such file or directory (2)
12-17 12:32:19.727: D/dalvikvm(1244): GC_FOR_ALLOC freed 55K, 3% free 8039K/8259K, paused 60ms, total 63ms
12-17 12:32:19.907: I/dalvikvm-heap(1244): Grow heap (frag case) to 19.900MB for 12582928-byte allocation
12-17 12:32:20.008: D/dalvikvm(1244): GC_CONCURRENT freed 1K, 2% free 20326K/20615K, paused 30ms+19ms, total 97ms
12-17 12:32:21.677: W/Ads(1244): No Google Analytics: Library Incompatible.
12-17 12:32:21.697: D/AndroidRuntime(1244): Shutting down VM
12-17 12:32:21.697: W/dalvikvm(1244): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-17 12:32:21.727: E/AndroidRuntime(1244): FATAL EXCEPTION: main
12-17 12:32:21.727: E/AndroidRuntime(1244): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.antiwal7amel/com.app.antiwal7amel.MenuActivity}: java.lang.NullPointerException
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.os.Looper.loop(Looper.java:137)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-17 12:32:21.727: E/AndroidRuntime(1244): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 12:32:21.727: E/AndroidRuntime(1244): at java.lang.reflect.Method.invoke(Method.java:511)
12-17 12:32:21.727: E/AndroidRuntime(1244): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-17 12:32:21.727: E/AndroidRuntime(1244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-17 12:32:21.727: E/AndroidRuntime(1244): at dalvik.system.NativeStart.main(Native Method)
12-17 12:32:21.727: E/AndroidRuntime(1244): Caused by: java.lang.NullPointerException
12-17 12:32:21.727: E/AndroidRuntime(1244): at com.app.antiwal7amel.MenuActivity.onCreate(MenuActivity.java:44)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.Activity.performCreate(Activity.java:5008)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-17 12:32:21.727: E/AndroidRuntime(1244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-17 12:32:21.727: E/AndroidRuntime(1244): ... 11 more
我正在使用它如下:
public class MenuActivity extends Activity {
AdView adView ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView ad = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest();
ad.loadAd(request);
在我的清单中也是:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
但我不知道问题出在哪里!我搜索了很多没有解决方案
答案 0 :(得分:1)
如果问题位于ad.loadAd(request);
,则adView
布局中不存在ID activity_main
可能存在问题。
或许AdRequest
的初始化可能有问题。也许你可以检查为什么其中一个元素是null
。因为当你知道其中哪一个是null
时,你可以尝试解决问题。