我读了一些将jsons发布到服务器的例子.
有人说:
OkHttp是Java提供的HttpUrlConnection接口的实现.它提供了用于编写内容的输入流,并且不知道(或关心)该内容的格式.
现在我想使用名称和密码的参数对URL进行正常发布.
这意味着我需要自己将名称和值对编码为流吗?
我有一个类似于void方法的模拟类
public class Mock {
public void method(String string) {
// doSomething
}
}
Run Code Online (Sandbox Code Playgroud)
我不关心这个方法做什么,但我想得到String发送.
这个String实际上是一个JSON格式的对象,我正在测试的方法是根据最初发送的字符串修改这个对象(很随意吧).
method(String json) {
Object obj = unparse(json);
obj.setRandomValue(random);
String parsed = parse(obj);
Mock.method(parsed);
}
Run Code Online (Sandbox Code Playgroud)
我想看看之前为null的"randomValue"是否实际上是在方法调用之后随机设置的.
最好的方法是拦截json,解析它并检查对象.
我试着按照这里的指南,但我遇到了一些问题.我正确地将搜索图标显示在操作栏中,但是我无法将其附加searchable configuration到SearchView.
我的res/menu/options_menu.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/search"
android:title="@string/search_title"
android:icon="@drawable/search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>
Run Code Online (Sandbox Code Playgroud)
我的res/xml/searchable.xml文件(注意:我必须在res文件夹中创建一个"xml"文件夹,因为一个文件夹不存在.我不认为这应该会有所不同吗?
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint" />
Run Code Online (Sandbox Code Playgroud)
我的res/values/strings.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Starting To Feel It</string>
<string name="single_post">Single Post View</string>
<string name="search">Search Activity</string>
<string name="action_settings">Settings</string>
<string name = "pagination_last">Last</string>
<string name = "pagination_next">Next</string>
<string name = "player_play">Play</string>
<string name = "player_previous">Previous</string>
<string name = "player_next">Next</string>
<string name = "player_playlist">Playlist</string>
<string name = "player_progress_bar">Progress Bar</string>
<string name="drawer_open">Open navigation …Run Code Online (Sandbox Code Playgroud) 我在AppBarLayout下面有一个ViewPager(带有工具栏和TabLayout).我无法理解为什么加载的片段的高度超过可用空间,即使没有这么大的元素,使标签可滚动.
这是主要的布局xml:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
正如你在我的片段中看到的那样,我有一个带有layout_alignParentBottom的Button,但我猜它会拉伸viewpager的高度太多.
这里是设计视图的布局:
我想将默认的Android搜索栏个性化为:

我读了大约9个补丁图像并创建了6个png图像.前三个是灰色进度条(progressDrawable),如下所示:
正确的形象

中心图像

左图

结果应该是:

蓝色图像代表进度,如下:
正确的形象

中心图像

左图

拇指如下:

我的问题是,如何使用九个补丁图像来生成与第一张图片完全相同的自定义搜索栏,如何将其应用于我的搜索栏?
在Tomcat 7上部署我们的应用程序后,我们得到了很多:
<date> org.apache.catalina.realm.LockOutRealm authenticate
WARNING: An attempt was made to authenticate the locked user "admin"
Run Code Online (Sandbox Code Playgroud)
在访问日志中我们发现了很多这样的:
91.121.4.141 - - <date> "GET /manager/html HTTP/1.1" 401 2486
Run Code Online (Sandbox Code Playgroud)
这似乎是法国ISP(OVH SAS).
发生什么了?他们试图登录,ping?它是僵尸网络吗?
我们如何防止这种登录尝试?
我之前从未使用过Gradle,所以我完全迷失了!
我已经添加了SlidingMenu作为库,我可以从我的项目访问所有SlindingMenu的东西,但是尝试编译会给我这个错误:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
Run Code Online (Sandbox Code Playgroud)
我正在使用Android Studio(所以IntelliJ),这是我的gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我有一个Java应用程序在MongoDB上执行一些聚合,但有时它只是挂起并抛出一个SocketTimeout异常.在异常之后,应用程序将运行正常(稍微,然后它可能会再次引发异常).
我刚刚发现这个解释似乎是可能的原因,但我不确定.
我初始化MongoClient并保持与DB的连接打开.我不确定这是否是一个问题,我应该每次都得到数据库,然后让数据库被垃圾收集(并关闭连接).
另一种方法可能是定期ping Mongo以保持连接池"新鲜".
使用的客户端是这样的:
public class DbClient {
private static MongoClient mongoClient;
private static MongoDatabase db;
private DbClient() {}
public static void init() throws Exception {
mongoClient = new MongoClient();
}
public static MongoDatabase getDB() {
if(mongoClient == null)
throw new IllegalStateException("Client not initialized!");
if(db == null) {
db = mongoClient.getDatabase("my_db");
}
return db;
}
}
Run Code Online (Sandbox Code Playgroud)
这是SocketTimeout的可能原因吗?
这是抛出的异常:
09:20:45.742 [qtp605535417-46] INFO org.mongodb.driver.connection - Closed connection [connectionId{localValue:16, serverValue:6562}] to myapp.com:27017 because there was a socket exception raised …Run Code Online (Sandbox Code Playgroud) 使用案例:
用户启动将加载验证码的应用程序.用户填写验证码并尝试下载一些信息.
问题:
如果用户在下载时旋转设备Activity则被销毁.在执行结束时,AsyncTask正在尝试更新被破坏的内容Activity,结果是"View not attached to window manager".
"错误的"解决方案:
我可以用a掩盖问题,android:configChanges="orientation|keyboardHidden|screenSize"但是这样布局不会更新为横向.
我在问什么:
是否可以更改方向并更改传递给上下文的"参考" AsyncTask?
这个答案建议检查对话框是否为空,但它不是我正在寻找的.
在这里,他建议使用WeakReference(这里有一个关于如何使用它的好片段),但我不明白它是否是我正在寻找的.
更明确一点,这就是我在onPostExecute中所做的:
@Override
protected void onPostExecute(Auto result) {
progress.dismiss();
new DownloaderCaptcha(context).execute("");
((EditText)context.findViewById(R.id.editTextCaptcha)).setText("");
context.findViewById(R.id.progrBar).setVisibility(View.VISIBLE);
context.findViewById(R.id.captcha).setVisibility(View.INVISIBLE);
if(result != null) {
Storage.storeHistory(context, result.getTarga().getValue());
Intent i = new Intent(context, MenuActivity.class);
i.putExtra("result", result);
context.startActivity(i);
} else {
ErrorDialog.show(context, error);
}
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
Git:恢复为先前的提交状态
我已经尝试过对我的代码进行一些更改,但是我搞砸了太多的东西(当你累了,而且已经很晚了,我就不会工作)而且我只想回到我上一次的提交.我不这样做,git add或者git commit很明显,如果我做的git pull一切都是最新的.
我认为这git checkout就是我需要的但它没有用......有什么帮助吗?