-1

我已经阅读了大约 2 打文章以及 Google 文档和我的代码,因为它只是给了我一个强制关闭框。这是我的代码

显现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ndai.funnys"
    android:versionCode="1" 
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8"  
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".GuysFunnysActivity"
            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="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  android:id="@+id/LinearLayout01"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="a14ffb06b21e68e"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, 12345678901234567890123456789012"
        ads:loadAdOnCreate="true"/>
</LinearLayout>

JAVA

package com.ndai.funnys;

import java.io.InputStream;
import java.net.URL;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.google.ads.*;

public class GuysFunnysActivity extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

我究竟做错了什么?这和我在其他网站上看到的完全一样。即使我使用了测试设备代码,我也尝试过具有相同问题的非 xml 版本。

LOGCAT

07-09 17:34:23.207: D/AndroidRuntime(729): Shutting down VM
07-09 17:34:23.207: W/dalvikvm(729): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-09 17:34:23.237: E/AndroidRuntime(729): FATAL EXCEPTION: main
07-09 17:34:23.237: E/AndroidRuntime(729): java.lang.RuntimeException: Unable to start activity ComponentInfo    {com.ndai.funnys/com.ndai.funnys.GuysFunnysActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.ads.AdView
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.os.Looper.loop(Looper.java:123)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.reflect.Method.invoke(Method.java:521)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-09 17:34:23.237: E/AndroidRuntime(729):  at dalvik.system.NativeStart.main(Native Method)
07-09 17:34:23.237: E/AndroidRuntime(729): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.ads.AdView
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.Activity.setContentView(Activity.java:1647)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.ndai.funnys.GuysFunnysActivity.onCreate(GuysFunnysActivity.java:20)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-09 17:34:23.237: E/AndroidRuntime(729):  ... 11 more
07-09 17:34:23.237: E/AndroidRuntime(729): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader    [/data/app/com.ndai.funnys-2.apk]
07-09 17:34:23.237: E/AndroidRuntime(729):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createView(LayoutInflater.java:466)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
07-09 17:34:23.237: E/AndroidRuntime(729):  ... 20 more
4

1 回答 1

1

在 Eclipse 中,所有 jar 都必须添加到 libs/ 或专门导出Order And ExportJava Build Path. 否则,jar 将不会捆绑到您的编译代码中,并且您的应用程序在引用 jar 文件时将在运行时失败。

于 2012-07-10T22:55:45.590 回答