2013-08-06 91 views
1

我想寫一個應用程序使用庫ActionBarSherlock的片段。SherlockFragmentActivity錯誤膨脹類

所以,我有一個問題。

我的佈局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_FrameLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <fragment 
     class="ru.neverdark.phototools.fragments.TitlesFragment" 
     android:id="@+id/main_titlesFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</FrameLayout> 

我的MainActivity類別:

package ru.neverdark.phototools; 

import ru.neverdark.phototools.log.Log; 
import com.actionbarsherlock.app.SherlockFragmentActivity; 
import android.os.Bundle; 

public class MainActivity extends SherlockFragmentActivity { 

    /* (non-Javadoc) 
    * @see android.app.Activity#onCreate(android.os.Bundle) 
    */ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Log.message("Enter"); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

} 

我TitlesFragment類:

package ru.neverdark.phototools.fragments; 

import ru.neverdark.phototools.Constants; 
import ru.neverdark.phototools.R; 
import ru.neverdark.phototools.log.Log; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import com.actionbarsherlock.app.SherlockListFragment; 

public class TitlesFragment extends SherlockListFragment { 
    boolean mDualPane; 
    int mCurrentCheckPosition = 0; 
    final String[] TITLES = getResources().getStringArray(R.array.main_menuTitles); 
    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     Log.message("Enter"); 
     super.onActivityCreated(savedInstanceState); 

     setListAdapter(new ArrayAdapter<String>(getActivity(), 
       R.layout.menu_item, 
       R.id.menuItem_label_title, 
       TITLES)); 

     View detailsFrame = getActivity().findViewById(R.id.main_detailFragment); 
     mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE; 

     if (savedInstanceState != null) { 
      mCurrentCheckPosition = savedInstanceState.getInt(Constants.CURRENT_CHOICE, 0); 
     } 

     if (mDualPane) { 
      getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
      showDetails(mCurrentCheckPosition); 
     } 
    } 


    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 

     outState.putInt(Constants.CURRENT_CHOICE, mCurrentCheckPosition); 
    } 

    @Override 
    public void onListItemClick(ListView listView, View view, int position, long id) { 
     showDetails(position); 
    } 

    private void showDetails(int index) { 
     mCurrentCheckPosition = index; 

     if (mDualPane == true) { 
      getListView().setItemChecked(index, true); 
      showFragment(index); 
     } else { 
      showActivity(index); 
     } 
    } 

    private void showFragment(int index) { 

    } 

    private void showActivity(int index) { 

    } 
} 

當我運行應用程序,我得到一個異常

調用setContentView函數時發生異常。

在此先感謝您的幫助。

+0

嘗試將''標記更改爲'' – Tarun

+0

在ActionBarSherlock示例文件中使用了,這很好用。然而,我嘗試了你的建議,但它並沒有幫助我:-( – Artem

+0

在'main_detailFragment'定義的佈局?? – Tarun

回答

0

問題已解決。

問題字符串:

final String[] TITLES = getResources().getStringArray(R.array.main_menuTitles); 

我改變這種爲:

final String[] TITLES = {"test1", "test2"};//getResources().getStringArray(R.array.main_menuTitles); 

它爲我工作的罰款。

塔倫,謝謝你幫助調查問題。

相關問題