当我使用片段时,我的应用程序崩溃了,它显然与GoogleMap
其中一个片段有关。
我已经将地图片段从更改为MapFragment
,SupportMapFragment
但没有帮助。
这是所有片段所在的主页(FragmentActivity
):
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
public class Fragments extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragments);
MainActivity fragment = new MainActivity();
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add(R.id.fragment_place, fragment);
transaction.commit();
}
public void onSelectFragment(View view) {
Fragment newFragment;
if (view == findViewById(R.id.add)) {
newFragment = new Add();
} else if (view == findViewById(R.id.map)) {
newFragment = new MainActivity();
} else {
newFragment = new MainActivity();
}
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.replace(R.id.fragment_place, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
}
日志猫:
09-30 15:03:19.257: W/dalvikvm(12895): threadid=1: thread exiting with uncaught exception (group=0x40ed5300)
09-30 15:03:19.265: E/AndroidRuntime(12895): FATAL EXCEPTION: main
09-30 15:03:19.265: E/AndroidRuntime(12895): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
09-30 15:03:19.265: E/AndroidRuntime(12895): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
09-30 15:03:19.265: E/AndroidRuntime(12895): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:284)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-30 15:03:19.265: E/AndroidRuntime(12895): at com.example.free.MainActivity.onCreateView(MainActivity.java:122)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.Activity.performStart(Activity.java:5018)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.ActivityThread.access$600(ActivityThread.java:142)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.os.Handler.dispatchMessage(Handler.java:99)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.os.Looper.loop(Looper.java:137)
09-30 15:03:19.265: E/AndroidRuntime(12895): at android.app.ActivityThread.main(ActivityThread.java:4931)
09-30 15:03:19.265: E/AndroidRuntime(12895): at java.lang.reflect.Method.invokeNative(Native Method)
09-30 15:03:19.265: E/AndroidRuntime(12895): at java.lang.reflect.Method.invoke(Method.java:511)
09-30 15:03:19.265: E/AndroidRuntime(12895): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-30 15:03:19.265: E/AndroidRuntime(12895): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
09-30 15:03:19.265: E/AndroidRuntime(12895): at dalvik.system.NativeStart.main(Native Method)
并且片段有点大,所以我将它粘贴到了 pastebin 上:
感谢你的协助!