有些用户收到此错误。
我使用视图组连续显示横幅添加。
然后我使用子视图作为程序,并在用户单击按钮时在视图之间来回切换。
我可以通过在子视图之间来回切换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 :(得分:0)
很奇怪,当您调用findViewById时,它们是在OnCreate方法中还是直接在适配器中给行充气?由于它与您的示例相关,findViewById方法仅保证在OnCreate方法中工作或特定行被夸大,因此在其他地方调用它可能会导致意外行为。
答案 1 :(得分:0)
看看这一行:
at com.jimbobga.mycoinsus.ProgramName$8.onClick(ProgramName.java:488)
如果在方向更改并且尚未分配视图后发生这种情况,那么您就遇到了问题。
答案 2 :(得分:0)
我遇到了同样的问题。
看一下这个回复:Issues With Adwhirl(Admob+Inmobi+..) 来自AdMob工作人员的Eric表示这是Android框架的一个问题。
您是否尝试使用:try / catch Throwable Exception包围OnClick()代码?