我在 Android 4.4.4中遇到错误,但它正在崩溃,但它在Andriod 5.0.1中完美运行
我正在Java Class
下面加载Mappublic class MapActivity extends Activity implements OnMapReadyCallback {
double longitude, latitude;
TextView m_tvNo, m_tvYes;
public static String m_Name, m_Location;
DBParse m_DBparser;
Context m_cont;
private LocationManager locationManager;
private GoogleMap googleMap;
Circle mapCircle;
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add_search_location_dialog_map); <<----in this line I am getting an error
以下是XML代码
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="@dimen/map_height" />
我收到以下错误
04-02 19:22:01.425: E/AndroidRuntime(20101): Process: com.example.achessapp, PID: 20101
04-02 19:22:01.425: E/AndroidRuntime(20101): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.achessapp/com.example.achessapp.fragment.settting.highrisk.map.MapActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2439)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread.access$800(ActivityThread.java:153)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.os.Handler.dispatchMessage(Handler.java:102)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.os.Looper.loop(Looper.java:157)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread.main(ActivityThread.java:5633)
04-02 19:22:01.425: E/AndroidRuntime(20101): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 19:22:01.425: E/AndroidRuntime(20101): at java.lang.reflect.Method.invoke(Method.java:515)
04-02 19:22:01.425: E/AndroidRuntime(20101): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
04-02 19:22:01.425: E/AndroidRuntime(20101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
04-02 19:22:01.425: E/AndroidRuntime(20101): at dalvik.system.NativeStart.main(Native Method)
04-02 19:22:01.425: E/AndroidRuntime(20101): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-02 19:22:01.425: E/AndroidRuntime(20101): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.Activity.setContentView(Activity.java:1997)
04-02 19:22:01.425: E/AndroidRuntime(20101): at com.example.achessapp.fragment.settting.highrisk.map.MapActivity.onCreate(MapActivity.java:57)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.Activity.performCreate(Activity.java:5312)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
04-02 19:22:01.425: E/AndroidRuntime(20101): ... 11 more
04-02 19:22:01.425: E/AndroidRuntime(20101): Caused by: java.lang.IllegalStateException: Fragment com.google.android.gms.maps.MapFragment did not create a view.
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.app.Activity.onCreateView(Activity.java:4890)
04-02 19:22:01.425: E/AndroidRuntime(20101): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-02 19:22:01.425: E/AndroidRuntime(20101): ... 21 more
答案 0 :(得分:0)
通过
进行扩展公共类MapActivity扩展FragmentActivity实现了OnMapReadyCallback {
您已将其扩展为仅限活动
答案 1 :(得分:0)
我已经通过将超级放在第一个
来解决了这个问题@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add_search_location_dialog_map);