我试图在前棒棒糖设备上使用矢量drawables.我按照这里的指示完成了所有操作,但我仍然遇到了这次崩溃.
的build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
}
apply plugin: 'com.android.application'
repositories {
maven { url 'http://maven.android-forever.com' }
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.test.app"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile "de.greenrobot:eventbus:2.4.0"
compile …Run Code Online (Sandbox Code Playgroud) 我正在尝试查看未分阶段的单个文件的更改.
首先我git status用来查看所有未分级的更改
然后例如:
git diff AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)
但我得到了这个输出
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
old mode 100755
new mode 100644
Run Code Online (Sandbox Code Playgroud)
这意味着什么以及如何查看特定文件的更改
标题解释了一切.我想在单击"硬件"菜单按钮时在操作栏中打开子菜单
这是代码,它第一次点击菜单工作正常.每隔一次它就会闪烁(打开并立即关闭)
private Menu mainMenu;
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
mainMenu = menu;
return true;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode) {
case KeyEvent.KEYCODE_MENU:
mainMenu.performIdentifierAction(R.id.more, 0);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud)
这是options.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/settings"
android:icon="@drawable/ic_menu_preferences"
android:showAsAction="ifRoom|withText"
android:title="Settings"/>
<item
android:id="@+id/about"
android:icon="@drawable/ic_menu_info_details"
android:showAsAction="ifRoom|withText"
android:title="About"/>
<item
android:id="@+id/more"
android:icon="@drawable/ic_menu_moreoverflow_normal_holo_dark"
android:showAsAction="always|withText"
android:title="More">
<menu>
<item
android:id="@+id/changelog"
android:icon="@drawable/ic_menu_recent_history"
android:showAsAction="ifRoom|withText"
android:title="Changelog"/>
<item
android:id="@+id/update"
android:icon="@drawable/ic_menu_refresh"
android:showAsAction="ifRoom|withText"
android:title="Update Check"/> …Run Code Online (Sandbox Code Playgroud) public String size(int size){
String hrSize = "";
int k = size;
double m = size/1024;
double g = size/1048576;
double t = size/1073741824;
DecimalFormat dec = new DecimalFormat("0.00");
if (k>0)
{
hrSize = dec.format(k).concat("KB");
}
if (m>0)
{
hrSize = dec.format(m).concat("MB");
}
if (g>0)
{
hrSize = dec.format(g).concat("GB");
}
if (t>0)
{
hrSize = dec.format(t).concat("TB");
}
return hrSize;
}
Run Code Online (Sandbox Code Playgroud)
这是一种应返回GB,MB,KB或TB大小的方法.输入值以KB为单位.例如1245的结果应该像1.21MB,但我得到的是1.00MB.
下面代码返回title的错误,没有意义
private val _error = MutableLiveData<String?>()
val error: LiveData<String?> get() = _error
_error.postValue(null) //Error Cannot set non-nullable LiveData value to null [NullSafeMutableLiveData]
Run Code Online (Sandbox Code Playgroud)
参数String的_error 显然是空的,我做错了什么?
这是我到目前为止,但是当我在拨号器中输入这个组合时没有任何反应
public class DialReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, final Intent intent) {
if (intent.getAction().equals(android.content.Intent.ACTION_NEW_OUTGOING_CALL)) {
String phoneNumber = intent.getExtras().getString( android.content.Intent.EXTRA_PHONE_NUMBER );
if(phoneNumber.equals("*#588637#")) {
Intent intent1 = new Intent(context , Activity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.startActivity(intent1);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
并在androidmanifest
<receiver
android:name=".receiver.DialReceiver"
android:exported="true"
android:process=":background"
tools:ignore="ExportedReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud) 即使我手动启动了交易,我仍然会收到此错误.
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.getTransaction();
if(!transaction.isActive())
{
transaction = session.beginTransaction();
}
accessToken = session.get(OAuthAccessToken.class, token);
Run Code Online (Sandbox Code Playgroud)
hibernate.cfg.xml
<property name="hibernate.connection.autoReconnect">true</property>
<!-- Use the C3P0 connection pool. -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Disable second-level cache. -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">3</property>
<!-- Bind the getCurrentSession() method to the thread. -->
<property name="current_session_context_class">thread</property>
<property name="hibernate.jdbc.batch_size">30</property>
Run Code Online (Sandbox Code Playgroud)
HibernateUtils
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
static
{
try
{
// Create …Run Code Online (Sandbox Code Playgroud) 什么是更好的for循环
这个:
for(int i = 0; i<someMethod(); i++)
{//some code
}
Run Code Online (Sandbox Code Playgroud)
要么:
int a = someMethod();
for(int i = 0; i<a; i++)
{//some code
}
Run Code Online (Sandbox Code Playgroud)
我们只是说someMethod()返回一些大的东西.
第一种方法将执行的someMethod()中的每个环因而降低速度,第二速度更快,但是,让我们说,有很多应用类似环路所以声明的一个可变VILL消耗更多的存储器.
那么更好,或者我只是愚蠢地思考.
有没有办法连接两个字符串(不是最终)而不分配内存?
例如,我有这两个字符串:
final String SCORE_TEXT = "SCORE: ";
String score = "1000"; //or int score = 1000;
Run Code Online (Sandbox Code Playgroud)
当我连接这两个字符串时,String会创建一个新对象.
font.drawMultiLine(batch, SCORE_TEXT + score, 50f, 670f);//this creates new string each time
Run Code Online (Sandbox Code Playgroud)
由于这是在主游戏循环中完成的(在一秒钟内执行约60次),因此有很多分配.
我可以不分配地以某种方式做到这一点吗
可能的重复:
ProcessBuilder 重定向输出
下面的代码:
ProcessBuilder pb = new ProcessBuilder(new String[] {"echo", "some text", ">", "test"});
Run Code Online (Sandbox Code Playgroud)
不断返回“ some text > test”。
我究竟做错了什么?
编辑:
这有效
ProcessBuilder pb = new ProcessBuilder(new String[] {"bash", "-c", "echo sometext > test"});
Run Code Online (Sandbox Code Playgroud)