2012-04-11 17 views
1

我在论坛上检查了类似的问题,但无法运行。 最后,我删除了一切不需要专注于错误,我离开这一块代码。但它仍然有出现NoClassDefFoundError在NoClassDefFoundError:AdWhirlLayout

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> 

的logcat:

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) 

大家有一个想法,能告诉我什么我不能see.Please。

最好的问候

+0

[请看这里](http://stackoverflow.com/a/9833655/420015) – adneal 2012-04-11 19:01:12

+0

这很快:)。我会读这个并回来。 Thx – user950117 2012-04-11 19:10:17

+0

那个链接是,我在找什么:)这解决了我的问题。谢谢。 – user950117 2012-04-11 20:45:55

回答

0

你一定要检查你的意见链接。基本上你需要通过将所需的库放在“libs”文件夹中来处理android中的所有依赖。 Eclipse不会为你自动生成,所以你必须自己做。将“libs”文件夹放在“res”文件夹中(不是bin/res,与src共享相同目录的res文件夹)。

另外,还要确保你在你的清单所有适当的声明,如果你正在启动等活动,需要为这些功能的特殊权限(使用互联网)等

+2

它实际上是一个“库”文件夹。 “s”很重要。 – adneal 2012-04-11 19:31:26

+0

^这。这很重要,但我在输入时忘了它。编辑并更正。 @aneal你应该发布答案而不是评论,这样你可以得到答案的功劳。 – 2012-04-12 19:48:30