【问题标题】:setContentView() giving errorsetContentView() 给出错误
【发布时间】:2013-07-27 05:58:51
【问题描述】:

setContentView() 在下面给出错误是我的代码:

  public class LocateUserInMap extends FragmentActivity {
    private GoogleMap mMap;    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_locate_user_in_map);
         mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
         mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
         final LatLng CIU = new LatLng(19.111693900000000000,72.911271500000000000);
         mMap.addMarker(new MarkerOptions().position(CIU).title("Friend"));
       //  findDirections(19.111693900000000000,72.911271500000000000,19.128203900000000000,72.928065000000060000, GMapV2Direction.MODE_DRIVING);
    }
}

错误:

这是我正在使用的库:

activity_locate_user_in_map.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".LocateUserInMap" >

 <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

</RelativeLayout>

我错过了什么... 请帮忙!!!

问候,
苏拉布

【问题讨论】:

  • 发布activity_locate_user_in_map.xml
  • 该应用程序似乎找不到 R.layout.activity_locate_user_in_map
  • @user2376920 你有解决方案吗?
  • 不...到目前为止还没有任何效果。
  • 清理项目无效。而且 maps.jar 在 GoogleAPI 中,我应该将其更改为 AndroidAPI 吗?

标签: android android-library


【解决方案1】:

您的布局文件R.layout.activity_locate_user_in_map 丢失,可能在另一个项目中或在正确的项目中但不知何故无法解决,请尝试清理项目

【讨论】:

  • 显然 com.google.android.gms.maps.MapFragment 不见了,看看Android SDK\extras\google\google_play_services\samples\maps的例子
  • 我的活动类的导入列表中有MapFragment
  • hımm google play services lib 怎么样?我给出的路径上的示例应该会有所帮助
  • 我引用了 google_play_service_lib 并添加到构建路径,但它被错误地输出为 [2013-07-27 16:43:59 - HelpMeRestart] 成功! [2013-07-27 16:43:59 - google-play-services_lib] 找不到 google-play-services_lib.apk! [2013-07-27 16:43:59 - HelpMeRestart] 在设备模拟器 5554 上启动活动 com.example.helpmerestart.Home 你能告诉我在哪里可以找到 google-play-services_lib.apk 文件
  • 他尝试添加 lib .jar 文件,位于 &lt;path tp android-sdk&gt;\extras\google\google_play_services\libproject\google-play-services_lib\bin\google-play-services_lib
【解决方案2】:

onCreate() 确实不需要 @SuppressLint("NewApi") 所以我猜你已经将你的项目设置为:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

然后尝试使用 Fragments 而不使用 support library。 您需要将导入更改为:

import android.support.v4.app.FragmentActivity;

并将任何调用更改为:

getFragmentManager()

getSupportFragmentManager()

您可能还想查看this question,了解有关 Fragment、FragmentActivity 和支持库的良好背景

【讨论】:

  • 我已经给出了我班级的完整代码。如果我删除 SuppressLint("NewApi") 它说 findFragmentById 需要 API11。此外,两个导入都显示从未使用过的警告。并且 min 和 max sdk 猜测是正确的。
  • 对不起,我不直接使用库,而是通过 ActionBarSherlock 使用,所以我没有代码可以在这里复制和粘贴。我已经编辑了答案的导入部分。请确保删除当前的 FragmentActivity 导入
  • 那么在不使用支持库的情况下尝试使用 Fragments 是什么意思?我需要删除android-support-v4.jar
  • 如果您要使用没有支持库的片段,您需要将 更改为 11+,那么您应该是 gtg
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2018-10-02
相关资源
最近更新 更多