2012-01-22 39 views
0

一部のユーザーにこのエラーが発生しています。NullPointerExceptionビュー間の切り替え時

ビューグループを使用して、バナーの追加を継続的に表示します。

私はプログラムの子ビューを使用して、ユーザーがボタンをクリックするとビュー間で切り替えることができます。

子ビュー間を6〜10回切り替えてクラッシュさせることができます。ここ

でのViewGroupのレイアウトである:ここ

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:myapp="http://schemas.android.com/apk/res/com.company.programname" 
    xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"  
    android:orientation="vertical"  
    android:background="@color/darkslategrey" 
    android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.adwhirl.AdWhirlLayout   
     android:id="@+id/adwhirl_layout" 
     android:gravity="center"   
     android:layout_width="fill_parent"   
     android:layout_height="52dp" 
    /> 
</LinearLayout> 

はのViewGroupを作成するコードである:ここ

setContentView(R.layout.viewgrouplayout); 
    llLinLay=(LinearLayout)findViewById(R.id.LinearLayout01); 
    liInflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

を切り出し無関係の片メイン子レイアウトである:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:id="@+id/MainLayout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


    <Button 
     android:id="@+id/MainShowAllDesiredButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/AnotherButton" 
     android:layout_toRightOf="@id/AButton" 
     android:textSize="15sp" 
     android:text="Show All Desired" 
     android:onClick="MainDesired" 
    /> 


    <ListView 
     android:id="@+id/ItemTypeList" 
     android:background="@color/aqua" 
     android:cacheColorHint="@color/aqua" 
     android:fastScrollEnabled="true" 
     android:layout_width="fill_parent" 
     android:layout_height="160dip" 
     android:layout_below="@id/SomeItem" 
    /> 

</RelativeLayout> 

ビューを作成するコードの例を次に示します。

ここでは
vAllDesired=liInflater.inflate(R.layout.alldesiredlayout,null); 
    vAllDesired.setId(7); 
    llLinLay.addView(vAllDesired); 
    final ListView lvAllDesired = (ListView)findViewById(R.id.AllDesiredList); 
    laAllDesiredAdapter = new AllDesiredListAdapter(this, alAllDesired);      
    lvAllCoinsDesired.setAdapter(laAllDesiredAdapter);   
    ViewGroup.LayoutParams AllDesiredParams = lvAllCoinsDesired.getLayoutParams(); 
    AllDesiredParams.height = AllCoinsDesiredHeight; 
    lvAllCoinsDesired.setLayoutParams(AllDesiredParams); 
    FillAllDesiredArray(); 

ビューを切り替えるために使用されるコードの例です。ここで

bReturnToMainScreen = (Button) findViewById(R.id.DesiredReturnToMainScreenButton); 
    bReturnToMainScreen.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View V) { 
     llLinLay.removeView(vAllDesired); 
     MainWindow(); 
     } 
    }); 

は、Androidデベロッパーのウェブサイトからのトレースです。プログラム内の行番号は必ずしも同じではありません。

java.lang.NullPointerException 
at android.webkit.WebView.requestFocus(WebView.java:6113) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1029) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1029) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1029) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1029) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1029) 
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1073) 
at android.view.ViewGroup.requestFocus(ViewGroup.java:1032) 
at android.view.View.requestFocus(View.java:3559) 
at android.view.ViewRoot.clearChildFocus(ViewRoot.java:1586) 
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:508) 
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:508) 
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:508) 
at android.view.ViewGroup.clearChildFocus(ViewGroup.java:508) 
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2207) 
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2181) 
at android.view.ViewGroup.removeView(ViewGroup.java:2129) 
at com.jimbobga.mycoinsus.ProgramName$8.onClick(ProgramName.java:488) 
at android.view.View.performClick(View.java:2411) 
at android.view.View$PerformClick.run(View.java:8819) 
at android.os.Handler.handleCallback(Handler.java:587) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:123) 
at android.app.ActivityThread.main(ActivityThread.java:4627) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:521) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
at dalvik.system.NativeStart.main(Native Method) 

答えて

0

興味があるだけ、あなたがfindViewByIdにあなたの電話を作っているとき、彼らはあなたが、アダプタ内の行を膨らませているのOnCreateメソッドまたは直接にいますか?ここでの例と関連して、findViewByIdメソッドはOnCreateメソッドまたは特定の行が拡張されている場所でのみ動作することが保証されているため、他の場所で呼び出すと予期しない動作が発生する可能性があります。この行で

+0

Javaファイル内には、onCreateメソッドが含まれています。いくつかはメソッド内にあり、一部は同じファイル内の関数内にあります。関数の中には、onCreateメソッドから呼び出されるものと、同じファイル内の他の関数によって呼び出されるものがあります。 – Bob

+0

広告会社のJARファイルでこれがエラーであることが判明しました。 jarは、広告を変更した後、制御をプログラムに戻さなかった。 – Bob

0

ルック:

at com.jimbobga.mycoinsus.ProgramName$8.onClick(ProgramName.java:488) 

向きが変更されたとビューが割り当てられていない後これが起こっている場合は、あなたが問題を抱えています。

+0

これは向きには関係ありません。あなたは効果なしで電話を回転することができます。表示されるadWhirl広告との相関があるようです。ビューが広告と同時に変更された場合、広告はコントロールをプログラムに戻しません。 – Bob

+0

それはちょっと考えました...しかし、このエラーのためにあなたは我々にこの行番号を教えてください。 – JoxTraex

+0

広告会社のJARファイルでこれがエラーであることが判明しました。 jarは、広告を変更した後、制御をプログラムに戻さなかった。 MdotMを使用しないでください。クラッシュは発生しません。 MdotMを使用する。一貫したクラッシュ。 – Bob

0

同じ問題が発生しています。

この応答を見てみましょう:Issues With Adwhirl(Admob+Inmobi+..) AdMobスタッフのEricによると、それはAndroidフレームワークの問題だと言います。

OnClick()コードを囲むようにしましたか:try/catch Throwable Exception?

関連する問題