它給我的錯誤在運行時關閉VM谷歌地圖V2讓我的位置
這裏logcat的
06-12 13:37:52.844: I/u(6937): Making Creator dynamically
06-12 13:37:53.675: I/Google Maps Android API(6937): Google Play services client version: 4452000
06-12 13:37:53.705: I/Google Maps Android API(6937): Google Play services package version: 4452034
06-12 13:37:55.287: I/fpp(6937): Making Creator dynamically
06-12 13:37:55.287: I/Google Maps Android API(6937): Google Play services client version: 4452000
06-12 13:37:55.507: D/dalvikvm(6937): GC_CONCURRENT freed 882K, 10% free 10018K/11043K, paused 28ms+13ms
06-12 13:37:56.608: D/AndroidRuntime(6937): Shutting down VM
06-12 13:37:56.608: W/dalvikvm(6937): threadid=1: thread exiting with uncaught exception (group=0x40aaa210)
06-12 13:37:56.688: E/AndroidRuntime(6937): FATAL EXCEPTION: main
06-12 13:37:56.688: E/AndroidRuntime(6937): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appmap.appmap/com.appmap.appmap.MainActivity}: java.lang.NullPointerException
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread.access$600(ActivityThread.java:127)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.os.Looper.loop(Looper.java:137)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread.main(ActivityThread.java:4448)
06-12 13:37:56.688: E/AndroidRuntime(6937): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 13:37:56.688: E/AndroidRuntime(6937): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 13:37:56.688: E/AndroidRuntime(6937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
06-12 13:37:56.688: E/AndroidRuntime(6937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
06-12 13:37:56.688: E/AndroidRuntime(6937): at dalvik.system.NativeStart.main(Native Method)
06-12 13:37:56.688: E/AndroidRuntime(6937): Caused by: java.lang.NullPointerException
06-12 13:37:56.688: E/AndroidRuntime(6937): at com.appmap.appmap.MainActivity.onCreate(MainActivity.java:29)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.Activity.performCreate(Activity.java:4465)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-12 13:37:56.688: E/AndroidRuntime(6937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
06-12 13:37:56.688: E/AndroidRuntime(6937): ... 11 more
代碼:
public class MainActivity extends FragmentActivity {
private GoogleMap gmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gmap.setMyLocationEnabled(true);
/*if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
'gMap'爲空。發佈'activity_main.xml'和片段佈局(如果有的話)。 – Raghunandan
<?xml version =「1.0」encoding =「utf-8」?> –
Raja
通過編輯您的帖子發佈這兩個佈局並命名它們。它是'activity_main.xml'還是'framgent_main.xml'? – Raghunandan