0

我有麻煩從一個片段打開一個新的活動我的活動包含一個地圖片段v2 ..其在api 4.0及以上..其工作罰款..但我面臨薑餅2.3麻煩.3它給了我一個強制關閉的錯誤。活動沒有開始在薑餅2.3.3

public class PerxListDetailFragment extends ListFragment { 

// Hashmap for ListView 
ArrayList<PerxDetailListModel> datalist ; 
protected PerxDetailListAdapter adapter; 
protected ListView listview; 
protected String url; 
protected static String id; 
protected static String name; 
//JSON names 
private static final String TAG_businessId    = "b_id"; 
private static final String TAG_businessName   = "businessName"; 
private static final String TAG_businessDescription  = "businessDescription"; 
private static final String TAG_businessLocation  = "businessLocation"; 
private static final String TAG_businessAddress   = "businessAddress"; 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
    Bundle bundle = new Bundle(); 
    bundle  = this.getArguments(); 
    SharedPreferences user_data = getActivity().getSharedPreferences("userData", 0); 

    String bid = user_data.getString("BUSINESSROLEID", null); 
    id   = bundle.getString("id"); 
    name = bundle.getString("name"); 

    url  = "http://projects.gaditek.com/mobile/ihirsto/services/getBusiness.php?businessCategoryID="+id +"&businessRole="+bid; 

    return inflater.inflate(R.layout.perx_list_detail, null, true); 
} 

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
      super.onActivityCreated(savedInstanceState); 
      TextView t = (TextView) getView().findViewById(R.id.perx_list_heading); 
      t.setText(name); 
      datalist = new ArrayList<PerxDetailListModel>(); 
      listview = getListView(); 
      if(datalist.isEmpty()){ 
       new DownloadData().execute(); 
      } 
      listview.setOnItemClickListener(new OnItemClickListener() 
      { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view,int position, long id) { 


        // Starting new intent 
        String venueName = datalist.get(position).getName().toString(); 
        String desc = datalist.get(position).getDescription().toString(); 
        String address = datalist.get(position).getAddress().toString(); 
        String maplong = datalist.get(position).getlongitude().toString(); 
        String maplat = datalist.get(position).getlatitude().toString(); 

        Intent intent = new Intent(getActivity().getApplicationContext(), PerxDetailedActivity.class); 


       intent.putExtra("heading", name); 
        intent.putExtra("venueName", venueName); 
        intent.putExtra("desc", desc); 
        intent.putExtra("address", address); 
        intent.putExtra("longitude", maplong); 
        intent.putExtra("latitude", maplat); 

       startActivity(intent); 



       } 


      }); 

     } 


     public void addFragment(Fragment fragment, boolean addToBackStack,int transition) 
     { 
      FragmentTransaction ft = getFragmentManager().beginTransaction(); 
      ft.replace(R.id.simple_fragment, fragment, null); 
      ft.setTransition(transition); 
      if (addToBackStack) 
       ft.addToBackStack(null); 
      ft.commit(); 
     } 

// =============================

@SuppressLint("NewApi") 
public class PerxDetailedActivity extends Activity{ 

    String headingName;String venueName;String desc ;String address; 
    String latitude;String longitude; 

     static LatLng HAMBURG; 
     private GoogleMap map; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.perx_detailed); 
     Intent intent = new Intent(); 

     Bundle extras = getIntent().getExtras(); 

     headingName = extras.getString("heading"); 
     venueName = extras.getString("venueName"); 
     desc  = extras.getString("desc"); 
     address  = extras.getString("address"); 
     longitude = extras.getString("longitude"); 
     latitude = extras.getString("latitude"); 
     Double longi = Double.parseDouble(longitude); 
     Double lati = Double.parseDouble(latitude); 
     HAMBURG = new LatLng(lati, longi); 


     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

     Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG) 
        .title(venueName)); 


    // Move the camera instantly to hamburg with a zoom of 15. 
     map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15)); 

     // Zoom in, animating the camera. 
     map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 



    } 

} 

登錄

06-01 18:26:16.546: E/AndroidRuntime(6549): FATAL EXCEPTION: main 
06-01 18:26:16.546: E/AndroidRuntime(6549): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gaditek.ihistro/com.gaditek.ihistro.PerxDetailedActivity}: android.view.InflateException: Binary XML file line #151: Error inflating class fragment 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread.access$1500(ActivityThread.java:132) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.os.Handler.dispatchMessage(Handler.java:99) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.os.Looper.loop(Looper.java:143) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread.main(ActivityThread.java:4196) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at java.lang.reflect.Method.invoke(Method.java:507) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at dalvik.system.NativeStart.main(Native Method) 
06-01 18:26:16.546: E/AndroidRuntime(6549): Caused by: android.view.InflateException: Binary XML file line #151: Error inflating class fragment 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.Activity.setContentView(Activity.java:1702) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at com.gaditek.ihistro.PerxDetailedActivity.onCreate(PerxDetailedActivity.java:40) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  ... 11 more 
06-01 18:26:16.546: E/AndroidRuntime(6549): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.gaditek.ihistro-1.apk] 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.createView(LayoutInflater.java:471) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 
06-01 18:26:16.546: E/AndroidRuntime(6549):  ... 21 more 

回答

1

我只是想出了愚蠢的我的問題就出在這裏

地圖=((MapFragment)getFragmentManager() .findFragmentById(R.id.map))的GetMap();

它應該是

地圖=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.map)。)的GetMap();需要

也@Glenn活動的規定由FragmentActivity而不是活動 延長..因此解決

3

你好這是一個兼容性錯誤的:

E/AndroidRuntime(6549): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.gaditek.ihistro-1.apk] 06-01 18:26:16.546:

找你試着g要在代碼中使用Fragment,但要使Fragments能夠在Gingerbread及其下運行,則必須從Google導入兼容性庫:請參閱Android Support Library和此Answer

因此,請務必將您的ActivityFragmentActivity和使用getSupportFragmentManager(),而不是getFragmentManager()

public void addFragment(Fragment fragment, boolean addToBackStack,int transition) 
     { 
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
      ft.replace(R.id.simple_fragment, fragment, null); 
      ft.setTransition(transition); 
      if (addToBackStack) 
       ft.addToBackStack(null); 
      ft.commit(); 
     } 
+0

我就開始活動面臨的問題..即PerxDetailedActivity這contian地圖V2庫的另一個片段 – Furqan

+0

呀這是正常的,但錯誤並不總是位於第一行。您必須添加[Android支持庫](http://developer.android.com/tools/extras/support-library.html)以使您的應用程序在薑餅上工作。 –

+0

是的整個應用程序正在使用片段,並且除了這部分工作正常...當我需要打開一個新的活動 – Furqan