我有一个扩展SherlockFragmentActivity并实现ActionBar.TabListener的活动。
这是xml的样子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_layout"
tools:context=".MyAppActivity" >
<fragment
android:id="@+id/tab_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:name="com.myapp.android.MyAppWebviewFragment" />
</LinearLayout>
它在setContentView上崩溃,其中activity_welcome是上面给出的xml。
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
...
MyAppActivity.java中的java.lang.IllegalStateException:154碎片 com.myapp.android.MyAppActivity没有创建视图。
这就是Fragment的onCreateView的样子:
public class MyAppWebviewFragment extends SherlockFragment{
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View web = inflater.inflate(R.layout.myapp_webview_fragment, container, false);
pullToRefreshView = (PullToRefreshWebView) web.findViewById(R.id.tab_content);
return web;
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Activity activity = getActivity();
if(url != null){
...
}
知道为什么会这样吗?
修改
堆栈跟踪:
java.lang.IllegalStateException: Fragment com.myapp.android.MyAppWebviewFragment did not create a view.
FragmentActivity.java:303 • android.support.v4.app.FragmentActivity.onCreateView
LayoutInflater.java:563 • android.view.LayoutInflater.createViewFromTag
LayoutInflater.java:623 • android.view.LayoutInflater.rInflate
LayoutInflater.java:408 • android.view.LayoutInflater.inflate
LayoutInflater.java:320 • android.view.LayoutInflater.inflate
LayoutInflater.java:276 • android.view.LayoutInflater.inflate
ActionBarSherlockCompat.java:840 • com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView
SherlockFragmentActivity.java:262 • com.actionbarsherlock.app.SherlockFragmentActivity.setContentView
MyAppActivity.java:154 • com.myapp.android.MyAppActivity.onCreate
Instrumentation.java:1047 • android.app.Instrumentation.callActivityOnCreate
ActivityThread.java:1617 • android.app.ActivityThread.performLaunchActivity
ActivityThread.java:1669 • android.app.ActivityThread.handleLaunchActivity
ActivityThread.java:117 • android.app.ActivityThread.access$1500
ActivityThread.java:937 • android.app.ActivityThread$H.handleMessage
Handler.java:99 • android.os.Handler.dispatchMessage
Looper.java:130 • android.os.Looper.loop
ActivityThread.java:3692 • android.app.ActivityThread.main
Method.java:-2 • java.lang.reflect.Method.invokeNative
Method.java:507 • java.lang.reflect.Method.invoke
ZygoteInit.java:842 • com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
ZygoteInit.java:600 • com.android.internal.os.ZygoteInit.main
NativeStart.java:-2 • dalvik.system.NativeStart.main