我的应用有问题。 一切都还可以,但是当我尝试将地图片段添加到我的活动中时,我的应用程序已停止。我认为一切都很好:我拥有自己的谷歌Api密钥,权限等。在我的代码中,我指出了我的代码中的新内容。
public class OpisMiejscaActivity extends FragmentActivity
{
Miejsce zMiejsce;
boolean mShowMap;
GoogleMap zMap;
private ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.opis_miejsca_activity);
getActionBar().setDisplayHomeAsUpEnabled(true);
//this line is new
mShowMap = GooglePlayServiceUtility.isPlayServiceAvailable(this) && initMap();
Bundle b = getIntent().getExtras();
zMiejsce = b.getParcelable(".model.Miejsce");
display();
}
//this initMap is new
private boolean initMap()
{
// TODO Auto-generated method stub
if(zMap == null)
{
MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
zMap = mapFrag.getMap();
}
return (zMap != null);
}
private void display()
{
TextView tv = (TextView) findViewById(R.id.titleText);
tv.setText(zMiejsce.getTytul1());
NumberFormat nf = NumberFormat.getCurrencyInstance();
tv = (TextView) findViewById(R.id.priceText);
tv.setText(nf.format(zMiejsce.getKoszt()));
tv = (TextView) findViewById(R.id.descText);
tv.setText(zMiejsce.getOpis());
//this if is new
if (mShowMap)
{
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(zMiejsce.getLatLng(), 5);
zMap.moveCamera(update);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.opis_miejsca, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_goto_action :
break;
case android.R.id.home:
break;
}
return false;
}
}
的活动:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >
<fragment
android:id="@+id/Fragment"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="2"
class="com.example.mysteriouspoland.OpisMiejscaActivityF" />
<!-- display map with map fragment -->
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="1" />
</LinearLayout>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mysteriouspoland"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<permission
android:name="com.example.mysteriouspoland.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mysteriouspoland.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mysteriouspoland.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailActivity"/>
<activity android:name=".GPSLicenseActivity"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="myapikeyfromgoogle" />
</application>
</manifest>
日志:
12-16 21:06:37.760: D/AndroidRuntime(586): Shutting down VM
12-16 21:06:37.760: W/dalvikvm(586): threadid=1: thread exiting with uncaught exception (group=0x413582a0)
12-16 21:06:37.875: E/AndroidRuntime(586): FATAL EXCEPTION: main
12-16 21:06:37.875: E/AndroidRuntime(586): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.mysteriouspoland/com.example.mysteriouspoland.OpisMiejscaActivity}; have you declared this activity in your AndroidManifest.xml?
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.Activity.startActivityForResult(Activity.java:3446)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.Activity.startActivityForResult(Activity.java:3407)
12-16 21:06:37.875: E/AndroidRuntime(586): at com.example.mysteriouspoland.MainActivity.onListItemClick(MainActivity.java:142)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.widget.AbsListView.performItemClick(AbsListView.java:1276)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.widget.AbsListView$1.run(AbsListView.java:3963)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.os.Handler.handleCallback(Handler.java:615)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.os.Handler.dispatchMessage(Handler.java:92)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.os.Looper.loop(Looper.java:137)
12-16 21:06:37.875: E/AndroidRuntime(586): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-16 21:06:37.875: E/AndroidRuntime(586): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 21:06:37.875: E/AndroidRuntime(586): at java.lang.reflect.Method.invoke(Method.java:511)
12-16 21:06:37.875: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-16 21:06:37.875: E/AndroidRuntime(586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-16 21:06:37.875: E/AndroidRuntime(586): at dalvik.system.NativeStart.main(Native Method)
将OpisMiejscaActivity添加到Manifest后,记录:
12-16 21:28:05.320: D/AndroidRuntime(7339): Shutting down VM
12-16 21:28:05.320: W/dalvikvm(7339): threadid=1: thread exiting with uncaught exception (group=0x413582a0)
12-16 21:28:05.365: E/AndroidRuntime(7339): FATAL EXCEPTION: main
12-16 21:28:05.365: E/AndroidRuntime(7339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mysteriouspoland/com.example.mysteriouspoland.OpisMiejscaActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.os.Looper.loop(Looper.java:137)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-16 21:28:05.365: E/AndroidRuntime(7339): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 21:28:05.365: E/AndroidRuntime(7339): at java.lang.reflect.Method.invoke(Method.java:511)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-16 21:28:05.365: E/AndroidRuntime(7339): at dalvik.system.NativeStart.main(Native Method)
12-16 21:28:05.365: E/AndroidRuntime(7339): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.Activity.setContentView(Activity.java:1924)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.example.mysteriouspoland.OpisMiejscaActivity.onCreate(OpisMiejscaActivity.java:46)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.Activity.performCreate(Activity.java:5206)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
12-16 21:28:05.365: E/AndroidRuntime(7339): ... 11 more
12-16 21:28:05.365: E/AndroidRuntime(7339): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
12-16 21:28:05.365: E/AndroidRuntime(7339): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-16 21:28:05.365: E/AndroidRuntime(7339): ... 21 more
12-16 21:28:05.390: D/dalvikvm(7339): GC_CONCURRENT freed 309K, 6% free 13573K/14407K, paused 16ms+13ms, total 51ms
答案 0 :(得分:0)
您没有将OpisMiejscaActivity
声明为清单中的活动
答案 1 :(得分:0)
正如您收到的错误所述:
您必须在application元素中包含以下声明:
<meta-data
<android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
因此,请将此元数据标记添加到xml清单文件中:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
答案 2 :(得分:0)
你的例外说:
ActivityNotFoundException:无法找到显式活动类{com.example.mysteriouspoland / com.example.mysteriouspoland.OpisMiejscaActivity};你有没有在AndroidManifest.xml中声明这个活动?
因此,您需要在清单文件的应用程序标记中提及您的活动,例如:
<activity android:name="com.example.mysteriouspoland.OpisMiejscaActivity" />
并将此元数据标记添加到xml清单文件中,如:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />