我在论坛上检查了类似的问题,但无法运行。最后,我删除了不需要关注错误的所有内容,并留下了那段代码。但它仍然会因 NoClassDefFoundError 而崩溃
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(TestActivity.this, key);
线。
我正在使用 AdWhirlSDK_Android_3.1.1,但也尝试了 AdWhirlSDK_Android_3.0.0。我有同样的错误。
Java 代码。
import com.adwhirl.AdWhirlLayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.LinearLayout.LayoutParams;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupAds();
}
private void setupAds() {
String key = "adwhirl_key";
int diWidth = 320;
int diHeight = 52;
float density = getResources().getDisplayMetrics().density;
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(TestActivity.this, key);
adWhirlLayout.setMaxWidth((int) (diWidth * density));
adWhirlLayout.setMaxHeight((int) (diHeight * density));
layout.addView(adWhirlLayout, layoutParams);
layout.invalidate();
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
日志猫:
04-11 17:59:50.451: E/AndroidRuntime(707): FATAL EXCEPTION: main
04-11 17:59:50.451: E/AndroidRuntime(707): java.lang.NoClassDefFoundError: com.adwhirl.AdWhirlLayout
04-11 17:59:50.451: E/AndroidRuntime(707): at com.testproject.TestActivity.setupAds(TestActivity.java:34)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.testproject.TestActivity.onCreate(TestActivity.java:18)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123)
04-11 17:59:50.451: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-11 17:59:50.451: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 17:59:50.451: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:507)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-11 17:59:50.451: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-11 17:59:50.451: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
有没有人有想法,可以告诉我我看不到的东西。请。
最好的祝福