Tag: java的

请求使用Android应用中使用的用于服务器Web的Google Places API KEY拒绝

我正在尝试从Android应用的Google商家信息API中获取信息。 为此,首先我在Google帐户中启用了此API。 其次,我为浏览器创建了一个API KEY。 由于其他API,我已经有了一个API KEY服务器。 所以,在我的代码中,我已经使用这两个密钥进行了测试,并且两者都得到了相同的结果! { “error_message”:“此服务需要API密钥。”, “html_attributions”:[], “结果”:[], “status”:“REQUEST_DENIED” } 我用来打电话的代码是…… @Override protected String doInBackground(LocationService… ls) { JSONObject result = new JSONObject(); URL url; HttpsURLConnection urlConnection; // Making HTTP request try { //Define connection url = new URL(“https://maps.googleapis.com/maps/api/place/nearbysearch/json”); urlConnection = (HttpsURLConnection)url.openConnection(); urlConnection.setRequestMethod(“POST”); urlConnection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”); urlConnection.setRequestProperty(“charset”, “utf-8”); urlConnection.setRequestProperty(“Accept”, “application/json”); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); //Send […]

如何将Access-Control-Allow-Origin添加到jetty服务器

我有一个jetty服务器来运行我的Web服务。 最近我开发了一个使用Web服务的程序并遇到了Access-Control-Allow-Origin问题。 如何将Access-Control-Allow-Origin:*添加到jetty嵌入式服务器。 下面是webappcontext代码。 public WebAppContext buildWebAppContext(){ webAppContext = new WebAppContext(); webAppContext.setDescriptor(webAppContext + “/WEB-INF/web.xml”); webAppContext.setResourceBase(“.”); webAppContext.setContextPath(“/posApplication”); webAppContext.setAttribute(“webContext”, webAppContext); return webAppContext; } 谢谢。

设置用户输入的超时

是否可以为用户输入设置计时器? 等待10秒 – 进行下一步操作等等。我的意思是 //wait several seconds{ String s = new BufferedReader(new InputStreamReader(System.in)).readLine(); //wait server seconds} //next operation and etc.

Android:Google Maps API – 更改地图工具栏的位置

我正在使用Google Maps API for Android。 单击标记时,以下代码启用右下角的地图工具栏 googleMap.getUiSettings().setMapToolbarEnabled(true); 但是,我希望此地图工具栏显示在地图的右上角,而不是默认的右下角位置。 我该怎么办?

在java中以螺旋方式移动图像

我正在尝试制作一个简单的动画介绍。 我有一个图像,我试图以顺时针螺旋运动从屏幕的左下角移动到屏幕的中心。 这是我现在使用的代码。 它只是将图像向上移动到中心: static ImageLoader il = new ImageLoader(); private static BufferedImage logo = il.load(“/logoNew.png”); private static Image power = il.gif(“http://sofzh.miximages.com/java/KSnus.gif”); static double y = 1024.0; public static void render(Graphics g){ if(y>(486/2)-128){ y = y-0.25; } if(draw){ g.drawImage(logo,(864/2)-128,(int)y,null); g.setColor(Color.WHITE); g.drawImage(power,10,10,null); } } if(draw)语句由其他东西激活。 我该如何移动图像。 我只是在不同点上以不同方式递增x和y吗? **编辑**我没有说明动议。 它从左下角到左上角到右上角到右下角到底部中心(中心)到屏幕的中心(中心)

在Android应用中为HttpClient更改OpenSSL库

我需要在我的项目中为HttpClient使用自定义OpenSSL库。 我为Android编译了libcrypto.so和libssl.so ,并将文件放在jniLibs文件夹中。 应用Heartbleed扫描仪看到它们。 System.loadLibrary(“crypto”)和System.loadLibrary(“ssl”)有效。 但现在我需要让HttpClient使用我的库而不是标准的SSL库。 但我不知道哪种方式可以移动以及如何移动。 我使用的是OpenSSL 1.0.1h和Android Studio 1.0.2。 提前感谢您的建议。

ANDROID:解析XML

我不是开发人员,我只是涉猎编程。 我从未理解的一个领域是XML解析。 可悲的是,对于我最新的“项目”,我需要为Android应用程序做这件事。 它是我为工作做的原型。 我有这个XML(一个模拟文件): 1275243 1077244 1077244 我有一些代码,让我得到每个的NodeList: inputStream = OpenHttpConnection(URL); Document document = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.parse(inputStream); document.getDocumentElement().normalize(); NodeList lineNodes = document.getElementsByTagName(“line”); 我不知道下一步该做什么。 我的代码似乎很长。 我用Google搜索了更好的方法,但是我发现了一些更清晰的代码,我无法开始工作。 有没有好的Android XML教程? 或者有人可以帮助我使用此代码? 我需要将每个进入HashMap,其中String是ID。 Line是显示的所有信息的类。 谢谢尼尔

UnsupportedClassVersionError的原因是什么?

java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:676) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:317) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at com.exe4j.runtime.LauncherEngine.launch(Unknown Source) at com.install4j.runtime.MacLauncher.main(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at apple.launcher.LaunchRunner.run(LaunchRunner.java:115) at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50) at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52) 我根本不明白这一点; […]

我如何检索随机值Firebase数据库

我有一个firebase数据库,其中有一棵树,看起来像这样 tvthemetunes airwolf value “url to air wolftheme” eastenders value “url to eastenders” knight rider value “url to nightrider” 等等… 在我的应用程序用户下载项目和项目下载电视主题将从url播放。 我可以让它在单个项目的值事件时正常工作。 我希望它从列表中随机选择一个值。 怎么能实现这个? 编辑可以使用循环视图方法,因为我的应用程序不包含任何 这是我的单项代码 protected Dialog onCreateDialog(int id) { switch (id) { case progress_bar_type: //Here is where i play the theme getthemetune(); pDialog = new ProgressDialog(c); pDialog.setTitle(MY Title); pDialog.setMessage(MY Message); pDialog.setIcon(R.mipmap.ic_launcher); pDialog.setIndeterminate(false); pDialog.setMax(100); […]

使用ObjectInputStream读取文件时出现EOFException

我基本上遇到了类似的问题: Java中的EOFexception在读取objectinputstream时 ,但我没有找到干净代码的答案。 答案表明,当读者到达文件结尾时, ObjectInputStream#readObject将抛出exception。 在网上寻找解决方案之后,我还没有找到解决方案。 对于这种情况可能是一个好的和干净的解决方案? 注意:我试过这个(但它看起来很难看并且不是干净的代码)。 我正在寻找更好的解决方案: ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); try { Object o; while ((o = ois.readObject()) != null) { if (o instanceof MyClass) { MyClass m = (MyClass)o; //use the object… } } } catch (EOFException eofex) { //do nothing } catch (IOException ioex) { throw ioex; //I […]