Google API v2无效(Google API v2 Not Work)
那我的代码!
ActivityMain
package com.example.googlemap; import com.google.android.gms.maps.SupportMapFragment; import android.os.Bundle; import android.support.v4.app.FragmentActivity; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle arg0) { // TODO Auto-generated method stub super.onCreate(arg0); setContentView(R.layout.activity_main); SupportMapFragment fragment = new SupportMapFragment(); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit(); } }
main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" 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=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" /> </RelativeLayout>
表现
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.googlemap" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <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" /> <!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. --> <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.googlemap.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAlBNf0GETrO0RdifpWH39ztBR7Cz1iyzE" /> </manifest>
和我的logcat
09-25 14:19:32.644: D/dalvikvm(2152): GC_CONCURRENT freed 154K, 2% free 16455K/16636K, paused 2ms+1ms, total 5ms 09-25 14:19:32.660: D/AndroidRuntime(2152): Shutting down VM 09-25 14:19:32.660: W/dalvikvm(2152): threadid=1: thread exiting with uncaught exception (group=0xa6208908) 09-25 14:19:32.664: E/AndroidRuntime(2152): FATAL EXCEPTION: main 09-25 14:19:32.664: E/AndroidRuntime(2152): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.access$600(ActivityThread.java:141) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Handler.dispatchMessage(Handler.java:99) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Looper.loop(Looper.java:137) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.main(ActivityThread.java:5041) 09-25 14:19:32.664: E/AndroidRuntime(2152): at java.lang.reflect.Method.invokeNative(Native Method) 09-25 14:19:32.664: E/AndroidRuntime(2152): at java.lang.reflect.Method.invoke(Method.java:511) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 09-25 14:19:32.664: E/AndroidRuntime(2152): at dalvik.system.NativeStart.main(Native Method) 09-25 14:19:32.664: E/AndroidRuntime(2152): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Activity.setContentView(Activity.java:1881) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:16) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Activity.performCreate(Activity.java:5104) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 09-25 14:19:32.664: E/AndroidRuntime(2152): ... 11 more 09-25 14:19:32.664: E/AndroidRuntime(2152): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bb.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bb.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.an.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bh.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bg.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at bob.onTransact(SourceFile:107) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Binder.transact(Binder.java:310) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a$4.b(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 09-25 14:19:32.664: E/AndroidRuntime(2152): ... 21 more
that my code!
ActivityMain
package com.example.googlemap; import com.google.android.gms.maps.SupportMapFragment; import android.os.Bundle; import android.support.v4.app.FragmentActivity; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle arg0) { // TODO Auto-generated method stub super.onCreate(arg0); setContentView(R.layout.activity_main); SupportMapFragment fragment = new SupportMapFragment(); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit(); } }
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" 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=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" /> </RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.googlemap" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <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" /> <!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. --> <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.googlemap.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAlBNf0GETrO0RdifpWH39ztBR7Cz1iyzE" /> </manifest>
and My logcat
09-25 14:19:32.644: D/dalvikvm(2152): GC_CONCURRENT freed 154K, 2% free 16455K/16636K, paused 2ms+1ms, total 5ms 09-25 14:19:32.660: D/AndroidRuntime(2152): Shutting down VM 09-25 14:19:32.660: W/dalvikvm(2152): threadid=1: thread exiting with uncaught exception (group=0xa6208908) 09-25 14:19:32.664: E/AndroidRuntime(2152): FATAL EXCEPTION: main 09-25 14:19:32.664: E/AndroidRuntime(2152): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.access$600(ActivityThread.java:141) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Handler.dispatchMessage(Handler.java:99) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Looper.loop(Looper.java:137) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.main(ActivityThread.java:5041) 09-25 14:19:32.664: E/AndroidRuntime(2152): at java.lang.reflect.Method.invokeNative(Native Method) 09-25 14:19:32.664: E/AndroidRuntime(2152): at java.lang.reflect.Method.invoke(Method.java:511) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 09-25 14:19:32.664: E/AndroidRuntime(2152): at dalvik.system.NativeStart.main(Native Method) 09-25 14:19:32.664: E/AndroidRuntime(2152): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Activity.setContentView(Activity.java:1881) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:16) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Activity.performCreate(Activity.java:5104) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 09-25 14:19:32.664: E/AndroidRuntime(2152): ... 11 more 09-25 14:19:32.664: E/AndroidRuntime(2152): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bb.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bb.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.an.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bh.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at maps.ag.bg.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at bob.onTransact(SourceFile:107) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.os.Binder.transact(Binder.java:310) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a$4.b(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a.a(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285) 09-25 14:19:32.664: E/AndroidRuntime(2152): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) 09-25 14:19:32.664: E/AndroidRuntime(2152): ... 21 more
原文:https://stackoverflow.com/questions/18998972
更新时间:2023-09-07 21:09
最满意答案
给这个镜头。 你可以改变任何你想要的rootdir,output_dir和百分比。
import os, shutil from random import choice rootdir = 'C:/images' output_dir = 'C:/copies' for subdir, dir, files in os.walk(rootdir): if files: for x in range(int(len(files) *.25)): to_copy = choice(files) shutil.copy(os.path.join(subdir, to_copy), os.path.join(output_dir, to_copy)) files.remove(to_copy)
Give this a shot. You can change the rootdir, output_dir, and percentage to whatever you want.
import os, shutil from random import choice rootdir = 'C:/images' output_dir = 'C:/copies' for subdir, dir, files in os.walk(rootdir): if files: for x in range(int(len(files) *.25)): to_copy = choice(files) shutil.copy(os.path.join(subdir, to_copy), os.path.join(output_dir, to_copy)) files.remove(to_copy)
相关问答
更多-
cmd命令显示文件夹所有文件是什么?[2023-09-24]
dir -
在这两个版本中, SourceFile = Dir()都在ActiveCell.Value = SourceFile之上。 这会导致在将文件名添加到列表之前跳过列表中的下一个文件而错过第一个文件。 更正代码: Dir()版本: FilePath = "C:\Test\" SourceFile = Dir(FilePath & "*.xls*") Do While SourceFile <> "" ActiveCell.Value = SourceFile ActiveCell.Offs ...
-
有两种方法可以解决这个问题,但我认为第二种方法是优越的。 1 - 在继续之前检查文件是否存在 只需添加一个File.exist?(f)检查您的代码: def transcode_process_1 Dir["path/file/source/*.mxf"].each do |f| next if !File.exist?(f) ..carry on as normal.. 2 - 使用队列(Threads包的一部分) 您可以使用可由所有线程访问的队列。 这以多种方式 ...
-
当然,一旦你停止一个宏,没有任何变量值的持久化 虽然观察到的行为是由于以下原因: 1) FileDialog对象保留在其IntialFileName属性中选择的最后一个路径 2)将空字符串作为“path”的Dir(path)函数将返回最后一个FileDialog运行时存储的IntialFileName路径中的第一个文件 所以当你重新运行宏时: NewDataFilePath是一个空字符串 a = Dir(NewDataFilePath)将返回匹配过滤器的IntialFileName路径中的第一个文件(如果有 ...
-
给这个镜头。 你可以改变任何你想要的rootdir,output_dir和百分比。 import os, shutil from random import choice rootdir = 'C:/images' output_dir = 'C:/copies' for subdir, dir, files in os.walk(rootdir): if files: for x in range(int(len(files) *.25)): to_cop ...
-
所有文件在一个dir,linux中(All files in one dir, linux)[2021-12-05]
行为是正确的,并且“按预期”。 for file in $InputDir'*'表示assign "/home/XXX/*" to $file (注意引号)。 既然你引用了星号,它现在不会被执行。 当shell看到echo $file ,它首先展开变量,然后进行glob扩展。 所以在第一步之后,它就会看到 echo /home/XXX/* 在全局扩展之后,它会看到: echo /home/XXX/fileA /home/XXX/fileB 直到现在,它才会执行命令。 在第二种情况下,在执行for之前扩展 ... -
Ruby Dir ['** / *']限制?(Ruby Dir['**/*'] limit?)[2021-07-24]
这是要求底层操作系统执行繁重操作可能更有效的时候之一,特别是如果你正在梳理大量文件: %x[ls -rU *.json | tail -10].split("\n") 在将打开shell的Mac OS上,按其创建日期以相反的顺序对所有'* .json'文件进行排序,返回最后十个。 名称将以字符串形式返回,因此split会将它们分成行末端的数组。 ls和tail命令非常快,并且在编译的C代码中完成它们的工作,避免了我们在Ruby中必须做的循环来过滤掉事情。 这方面的缺点是它依赖于操作系统。 Windows可 ... -
为什么“dir /”和“dir”与rsync的区别[关闭](Why this difference between “dir/” and “dir” with rsync [closed])[2023-04-24]
您所有问题的答案都在手册页中: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the d ... -
Dir()函数“。”和“..”(Dir() function “.” and “..”)[2022-11-21]
'' 表示当前目录 '..'表示父目录 它们由'dir'命令返回。 在你的情况下(以及我见过的任何其他)他们只是妨碍了,所以代码特别忽略了它们 '.' means the current directory '..' means the parent directory They are returned by the 'dir' command. In your case (and any other I have seen) they just get in the way and so the cod ... -
我会说去正则表达式。 Private Sub TeamTxtExists() Dim Path As String, Pattern As String, FileFound As String Dim REGEX As Object, Matches As Object Dim oFSO As Object, oFolder As Object, oFile As Object Path = "D:\Personal\Stack Overflow\" 'Modify a ...