我正在使用volley来获取API的响应,但响应包含STATE_ID:STATE_NAME对(i.e. value:value pair)
,我需要在不同的字符串中使用双方的值.我需要将这些值放入微调器中,以便当用户选择时State
我也可以获得相应的ID.
// JSON response
{
"1": "West bengal",
"3": "Himachal Pradesh",
"4": "Maharashtra",
"11": "Queensland"
}
Run Code Online (Sandbox Code Playgroud)
我的守则
public class MainActivity extends AppCompatActivity {
private static final String STATE = "MY_API";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void login(View v){
loginRequest();
}
private void loginRequest() {
StringRequest stringRequest = new StringRequest(Request.Method.POST, STATE,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public …
Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌应用引擎开发应用程序后端,使用 eclipse 作为 IDE,我想使用谷歌的 Firebase SDK。在集成页面中,Google 提供了以下选项来安装后端的 SDK:
我们将 Firebase Java SDK 发布到 Maven 中央存储库。要安装该库,您只需在build.gradle
文件中将其声明为依赖项:
dependencies {
compile 'com.google.firebase:firebase-server-sdk:[3.0.0,)'
}
Run Code Online (Sandbox Code Playgroud)
如果您使用 Maven 构建您的应用程序,您可以将以下依赖项添加到您的pom.xml
:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-server-sdk</artifactId>
<version>[3.0.0,)</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
后端不使用 Gradle 构建,我不确定 Maven 选项。到现在为止,我总是下载我使用的库的 jars
谢谢。
java.lang.OutOfMemoryError: Failed to allocate a 1465140570 byte allocation with 1622964 free bytes and 509MB until OOM
at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:316)
at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:526)
at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:548)
at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:392)
at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:155)
at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:85)
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改工具栏的文本颜色,但无济于事。这是我的代码。
样式文件
<!-- Base application theme. -->
<style name="BasicTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="ToolbarTheme" parent="BasicTheme">
<item name="android:textColor">@color/text_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
工具_lay
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:appo="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
android:elevation="10dp"
android:background="@color/colorPrimary"
appo:theme="@style/ToolbarTheme"
>
Run Code Online (Sandbox Code Playgroud)
活动_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="testing.theo.aelfootballclub.MainActivity"
android:background="#3d827e">
<include
android:id="@+id/toolbar"
layout="@layout/tool_lay"
/>
<LinearLayout
android:padding="20dp"
android:background="#6e7398"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/user_name"
android:hint="Userame"
android:layout_width="250dp"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/user_pass"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginTop="20dp"
android:hint="???????"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_gravity="center_horizontal"
android:text="???????"
android:layout_marginTop="20dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud) import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = this.openOrCreateDatabase("Practice", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS blah (subjects VARCHAR, notes VARCHAR, amount VARCHAR");
}
Run Code Online (Sandbox Code Playgroud)
错误日志:
E/SQLiteLog:(1)在"VARCHAR"附近:语法错误06-30 23:46:21.834 11420-11420/com.asd.sqltesting D/AndroidRuntime:关闭VM 06-30 23:46:21.835 11420-11420/com.asd.sqltesting E/AndroidRuntime:FATAL EXCEPTION:main进程:com.asd.sqltesting,PID:11420 java.lang.RuntimeException:无法启动活动ComponentInfo {com.asd.sqltesting/com.asd.sqltesting.MainActivity} :android.database.sqlite.SQLiteException:near"VARCHAR":语法错误(代码1):,同时编译:CREATE TABLE IF NOT EXISTS blah(subject VARCHAR,notes VARCHAR,amount VARCHAR at android.app.ActivityThread.performLaunchActivity(ActivityThread) .java:2298)在Android.app.ActivityThread.access $ 800(ActivityThread.java:144)的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)android.app.ActivityThread $ H.handleMessage(ActivityThread.java) :1278)android.app.Handler.dispatchMessage(Handler.java:102)android.app.Looper.loop(Looper.java:135)android.app.ActivityThread.main(ActivityThre)ad.java:5221)at java.lang.reflect.Method.invoke(Native Method)at java.lang.reflect.Method.invoke(Method.java:372)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.运行(ZygoteInit.java:899)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)引起:android.database.sqlite.SQLiteException:near"VARCHAR":语法错误(代码1): ,同时编译:CREATE TABLE IF NOT EXISTS …
我非常清楚我在这里解析为Integer的值是Long值.
问题是:为什么它在Pre-Marshmallow工作?
这是我的代码:
public void print(long mili) {
Long serverUptimeSeconds =
(mili - System.currentTimeMillis()) / 1000;
String serverUptimeText =
String.format("%02d%02d%02d%02d",
Math.abs(serverUptimeSeconds) / 86400,
(Math.abs(serverUptimeSeconds) % 86400) / 3600,
((Math.abs(serverUptimeSeconds) % 86400) % 3600) / 60,
((Math.abs(serverUptimeSeconds) % 86400) % 3600) % 60
);
// compiler is giving error at this line in Marshmallow 6.0.1 only
tv.setValue(Integer.parseInt(serverUptimeText), false);
}
Run Code Online (Sandbox Code Playgroud)
我的职责:
public void setValue(int value, boolean withAnimation) {
mCurrentValue = value;
int tempValue = value;
for (int …
Run Code Online (Sandbox Code Playgroud)