2011-04-11 70 views
0

我有我的應用程序非常簡單的設置,以測試的AdWhirlAdwhirl導致我的Android應用程序崩潰?

import android.app.Activity; 
import android.os.Bundle; 
import android.view.ViewGroup.LayoutParams; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import com.adwhirl.AdWhirlLayout; 

public class testads extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.testads); 

     LinearLayout layout = (LinearLayout) findViewById(R.id.layout_main); 
     AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my_ADWHIRLSDKCODE"); 
     RelativeLayout.LayoutParams adWhirlLayoutParams = 
       new RelativeLayout.LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT); 
     layout.addView(adWhirlLayout, adWhirlLayoutParams); 
     layout.invalidate(); 
    } 
} 

和佈局文件如下

<?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:id="@+id/layout_main" 
    > 
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    <AdWhirlLayout android:id="@+id/adwhirl_layout"/> 
</LinearLayout> 

當我運行它,應用程序崩潰...這應該如此簡單,我做錯了什麼?

編輯:我很抱歉之前...這裏是

04-11 17:21:36.215: ERROR/AndroidRuntime(2084): FATAL EXCEPTION: main 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vicvic.android/com.vicvic.android.testads}: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.os.Handler.dispatchMessage(Handler.java:99) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.os.Looper.loop(Looper.java:123) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at java.lang.reflect.Method.invoke(Method.java:521) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at dalvik.system.NativeStart.main(Native Method) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class AdWhirlLayout 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.Activity.setContentView(Activity.java:1647) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at com.vicvic.android.testads.onCreate(testads.java:18) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  ... 11 more 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084): Caused by: java.lang.ClassNotFoundException: android.view.AdWhirlLayout in loader dalvik.system.PathClassLoader[/data/app/com.vicvic.android-2.apk] 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.createView(LayoutInflater.java:466) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 
04-11 17:21:36.215: ERROR/AndroidRuntime(2084):  ... 20 more 
04-11 17:21:36.375: WARN/ActivityManager(66): Force finishing activity com.vicvic.android/.testads 
04-11 17:21:36.895: WARN/ActivityManager(66): Activity pause timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads} 
04-11 17:21:42.635: DEBUG/dalvikvm(185): GC_EXPLICIT freed 149 objects/10872 bytes in 86ms 
04-11 17:21:47.308: WARN/ActivityManager(66): Activity destroy timeout for HistoryRecord{44f65b98 com.vicvic.android/.testads} 
04-11 17:21:47.735: DEBUG/dalvikvm(267): GC_EXPLICIT freed 31 objects/1400 bytes in 178ms 
04-11 17:22:29.135: DEBUG/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol 

回答

2

沒有錯誤信息它只是猜測。 嘗試類似 在您的XML使用AdWhirlLayout類的包名稱

+0

是有道理的,我附上了logcat – vasion 2011-04-11 14:29:48

1

沒有從logcat的錯誤,我們只能猜測我不包括日誌錯誤:

您已經定義AdWhirlLayout你的XML,但你在onCreate中創建一個新的。我想你也應該爲你的adwhirllayout使用findViewById,你不應該將它添加到你的layout_main中,因爲它已經在那裏。

那只是一種猜測,因爲你沒有提供的錯誤信息......

編輯:您應該決定:你在XML佈局(除了遵循什麼@Hache說),或做在的onCreate。不要嘗試混合兩種方式,特別是不添加相同的觀點兩次(一次在xml中,一次在onCreate)

+0

有道理,我附上了logcat – vasion 2011-04-11 14:27:56

+0

我更新了我的答案。嘗試添加您的XML文件中的視圖,只需使用findViewById()onCreate() – WarrenFaith 2011-04-11 14:31:27