2012-02-09 1 views
1

이 포럼에서 질문하는 비슷한 질문의 수로 판단 할 때 일반적인 오류가있는 것으로 확인되었지만 이에 대한 답을 찾지 못했습니다.조각으로 TabActivity 바꾸기 : 클래스 조각을 부 풀리는 오류가 발생했습니다.

나는 더 이상 사용되지 않는 tabActivity를 대체하기 위해 조각을 사용하려고합니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:name="fr.partisocialite.psa.activity.TabsFragment" 
     android:id="@+id/tabs_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

</LinearLayout> 

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 

public class MediaActivity extends FragmentActivity{ 

    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.psa_media); 
     } 

가 나는 또한 안드로이드 교체 시도했다 : 여기

클래스

이름 것은 내 로그 캣입니다 :

02-09 10:07:48.738: E/AndroidRuntime(1713): FATAL EXCEPTION: main 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): 
> java.lang.RuntimeException: Unable to start activity 
> ComponentInfo{fr.partisocialiste.psa/fr.partisocialiste.psa.activity.MediaActivity}: 
> android.view.InflateException: Binary XML file line #7: Error 
> inflating class fragment 02-09 10:07:48.738: E/AndroidRuntime(1713): 
> at 
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.ActivityThread.startActivityNow(ActivityThread.java:1487) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.widget.TabHost.setCurrentTab(TabHost.java:326) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:456) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.view.View.performClick(View.java:2485) 02-09 10:07:48.738: 
> E/AndroidRuntime(1713): at 
> android.view.View$PerformClick.run(View.java:9080) 02-09 10:07:48.738: 
> E/AndroidRuntime(1713): at 
> android.os.Handler.handleCallback(Handler.java:587) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.os.Handler.dispatchMessage(Handler.java:92) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.os.Looper.loop(Looper.java:130) 02-09 10:07:48.738: 
> E/AndroidRuntime(1713): at 
> android.app.ActivityThread.main(ActivityThread.java:3683) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> java.lang.reflect.Method.invokeNative(Native Method) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> java.lang.reflect.Method.invoke(Method.java:507) 02-09 10:07:48.738: 
> E/AndroidRuntime(1713): at 
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> dalvik.system.NativeStart.main(Native Method) 02-09 10:07:48.738: 
> E/AndroidRuntime(1713): Caused by: android.view.InflateException: 
> Binary XML file line #7: Error inflating class fragment 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.view.LayoutInflater.inflate(LayoutInflater.java:408) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.view.LayoutInflater.inflate(LayoutInflater.java:320) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.view.LayoutInflater.inflate(LayoutInflater.java:276) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.Activity.setContentView(Activity.java:1657) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> fr.partisocialiste.psa.activity.MediaActivity.onCreate(MediaActivity.java:14) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): ... 18 more 02-09 
> 10:07:48.738: E/AndroidRuntime(1713): Caused by: 
> android.support.v4.app.Fragment$InstantiationException: Unable to 
> instantiate fragment fr.partisocialite.psa.activity.TabsFragment: make 
> sure class name exists, is public, and has an empty constructor that 
> is public 02-09 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.support.v4.app.Fragment.instantiate(Fragment.java:332) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.support.v4.app.Fragment.instantiate(Fragment.java:300) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:248) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): ... 27 more 02-09 
> 10:07:48.738: E/AndroidRuntime(1713): Caused by: 
> java.lang.ClassNotFoundException: 
> fr.partisocialite.psa.activity.TabsFragment in loader 
> dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/fr.partisocialiste.psa-1.apk] 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
> 02-09 10:07:48.738: E/AndroidRuntime(1713): at 
> java.lang.ClassLoader.loadClass(ClassLoader.java:551) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> java.lang.ClassLoader.loadClass(ClassLoader.java:511) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  at 
> android.support.v4.app.Fragment.instantiate(Fragment.java:322) 02-09 
> 10:07:48.738: E/AndroidRuntime(1713):  ... 30 more 02-09 10:07:48.804: 
> I/global(1713): Loaded time zone names for en_US in 1110ms. 02-09 
> 10:07:49.957: D/dalvikvm(1713): GC_CONCURRENT freed 908K, 51% free 
> 3705K/7431K, external 2360K/3860K, paused 2ms+2ms 02-09 10:07:50.242: 
> I/global(1713): Loaded time zone names for en_US in 1147ms. 02-09 
> 10:07:50.410: D/dalvikvm(1713): GC_FOR_MALLOC freed 598K, 51% free 
> 3698K/7431K, external 2360K/3860K, paused 38ms 02-09 10:07:50.574: 
> D/dalvikvm(1713): GC_FOR_MALLOC freed 164K, 50% free 3779K/7431K, 
> external 2360K/3860K, paused 51ms 02-09 10:07:50.593: 
> D/dalvikvm(1713): GC_FOR_MALLOC freed 243K, 50% free 3773K/7431K, 
> external 2360K/3860K, paused 15ms 02-09 10:07:50.609: 
> D/dalvikvm(1713): GC_FOR_MALLOC freed <1K, 47% free 4010K/7431K, 
> external 2360K/3860K, paused 16ms 02-09 10:07:50.699: 
> D/dalvikvm(1713): GC_CONCURRENT freed 1194K, 49% free 3982K/7687K, 
> external 2360K/3860K, paused 2ms+3ms 

고마워, 내가 성공하지 못했습니다 내 logCat을 더 잘 보이게 만드는 것에 대해, 미안합니다. 여기

내 클래스 TabsFragment입니다

< < < < <

package fr.partisocialiste.psa.activity; 

import fr.partisocialiste.psa.R; 
import android.app.Activity; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TabHost; 
import android.widget.TextView; 
import android.widget.TabHost.OnTabChangeListener; 
import android.widget.TabHost.TabSpec; 

public class TabsFragment extends Fragment implements OnTabChangeListener{ 

    private static final String TAG = "FragmentTabs"; 
    public static final String TAB_HOLL = "Hollande"; 
    public static final String TAB_PS = "PS"; 

    private View mRoot; 
    private TabHost mTabHost; 
    private int mCurrentTab; 

    public TabsFragment(){ 
     super(); 
    } 


    @Override 
    public void onAttach(Activity activity) { 
     super.onAttach(activity); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     mRoot = inflater.inflate(R.layout.tabs_fragment, null); 
     mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); 
     setupTabs(); 
     return mRoot; 
    } 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     setRetainInstance(true); 

     mTabHost.setOnTabChangedListener(this); 
     mTabHost.setCurrentTab(mCurrentTab); 
     // manually start loading hollande 
     updateTab(TAB_HOLL, R.id.tab_hollande); 
    } 

    private void setupTabs() { 
     mTabHost.setup(); // important! 
     mTabHost.addTab(newTab(TAB_HOLL, R.string.tab_hollande, R.id.tab_hollande)); 
     mTabHost.addTab(newTab(TAB_PS, R.string.tab_ps, R.id.tab_ps)); 
    } 

    private TabSpec newTab(String tag, int labelId, int tabContentId) { 
     Log.d(TAG, "buildTab(): tag=" + tag); 

     View indicator = LayoutInflater.from(getActivity()).inflate(
       R.layout.tab, 
       (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); 
     ((TextView) indicator.findViewById(R.id.text)).setText(labelId); 

     TabSpec tabSpec = mTabHost.newTabSpec(tag); 
     tabSpec.setIndicator(indicator); 
     tabSpec.setContent(tabContentId); 
     return tabSpec; 
    } 

    @Override 
    public void onTabChanged(String tabId) { 
     if (TAB_HOLL.equals(tabId)) { 
      updateTab(tabId, R.id.tab_hollande); 
      mCurrentTab = 0; 
      return; 
     } 
     if (TAB_PS.equals(tabId)) { 
      updateTab(tabId, R.id.tab_ps); 
      mCurrentTab = 1; 
      return; 
     } 

    } 

    private void updateTab(String tabId, int placeholder) { 
     FragmentManager fm = getFragmentManager(); 
     if (fm.findFragmentByTag(tabId) == null) { 
      if(TAB_HOLL.equals(tabId)){ 
//    fm.beginTransaction() 
//    .replace(placeholder, new MyListFragment(tabId), tabId) 
//    .commit(); 
      } 
      else if(TAB_PS.equals(tabId)){ 
//    fm.beginTransaction() 
//    .replace(placeholder, new MyListFragment(tabId), tabId) 
//    .commit(); 
      } 
     } 
    } 

} 
+0

여기 API 레벨은 무엇입니까? – Ksice

+0

호환성 라이브러리가있는 Android 2.2는 API 4 –

답변

0

문제는

android.support.v4.app.Fragment $있는 InstantiationException 다음과 같습니다 인스턴스화 할 수 없습니다 fragment fr.partisocialite.psa.activity.TabsFragment : 클래스 이름이 있는지, public인지, 빈 생성자가 있는지 확인하십시오. public

위 항목을 확인하고 그에 따라 수정하십시오.

+0

에서 사용할 수 있다고 생각합니다. 불행히도 클래스 이름이 존재하고 공개되며 빈 생성자가 공개되어 있습니다! –

+0

그것은 슈퍼 생성자 – jeet

+0

을 호출하는 것입니다. 실제로는 아니지만 아무 것도 변경하지 않습니다 ... 사본을 복사했습니다. 내 tabsFragment 클래스 –

0

일반적으로 inflater.inflate (R.layout.tabs_fragment, container, false)를 사용합니다. 하지만 문제는 이것이다 :

<fragment 
     android:name="fr.partisocialite.psa.activity.TabsFragment"... 

당신이 오류 전에이 경고처럼이있는 경우가

<fragment 
     class="fr.partisocialite.psa.activity.TabsFragment"... 
+0

나는 확실히 그것을 시도했습니다, 나는 원래의 글에서 그것을 썼지 만, 불행히도 그것은 내 문제를 해결하지 못합니다. 이름이나 수업인지 확실하지 않았기 때문에 나는 무언가를 바꿀 때마다 두 가지를 시도합니다. –

0

확인하려면 :

05-16 10:08:00.033: W/dalvikvm(1695): Unable to resolve superclass of Lmy/fragment/test/FragmentTestActivity; (7) 
05-16 10:08:00.076: W/dalvikvm(1695): Link of class 'Lmy/fragment/test/FragmentTestActivity;' failed 

이 그렇다면, 시도 :

구성 Java 빌드 경로 -> 주문 및 내보내기 탭 -> 확인란 설정 android-support-v4.jar

(기존 API를 먼저 제거해야 할 수도 있습니다.)