我正在为我的应用程序使用片段和齐射但是当我尝试初始化凌空RequestQueue我的应用程序崩溃并抛出OutOfMemoryError时,它试图将1.8 GB的数据初始化到内存中
05-12 18:00:51.947 10765-10781/com.sellcom.tracker W/dalvikvm? 1802465107 byte allocation exceeds the 67108864 byte maximum heap size
05-12 18:00:51.947 10765-10781/com.sellcom.tracker I/dalvikvm-heap? Forcing collection of SoftReferences for 1802465107-byte allocation
05-12 18:00:51.981 10765-10781/com.sellcom.tracker D/dalvikvm? GC_BEFORE_OOM freed 330K, 6% free 8660K/9207K, paused 34ms, total 34ms
05-12 18:00:51.982 10765-10781/com.sellcom.tracker E/dalvikvm-heap? Out of memory on a 1802465107-byte allocation.
05-12 18:00:51.982 10765-10781/com.sellcom.tracker I/dalvikvm? "Thread-1108" prio=5 tid=11 RUNNABLE
05-12 18:00:51.982 10765-10781/com.sellcom.tracker I/dalvikvm? | group="main" sCount=0 dsCount=0 obj=0x41718598 self=0x51363d10
05-12 18:00:51.982 10765-10781/com.sellcom.tracker I/dalvikvm? | sysTid=10781 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1362874264 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Volley发送请求,但我无法确定如何使其工作.
我需要发送一个带有JSON编码数据的POST请求作为正文,但经过几个小时尝试不同的东西后,我仍然无法使其工作.
这是我当前的请求代码:
User user = User.getUser(context);
String account = user.getUserAccount();
String degreeCode = user.getDegreeCode();
final JSONObject body = new JSONObject();
try {
body.put(NEWS_KEY, 0);
body.put(NEWS_DEGREE, degreeCode);
body.put(NEWS_COORDINATION, 0);
body.put(NEWS_DIVISION, 0);
body.put(NEWS_ACCOUNT, account);
} catch (JSONException e) {
e.printStackTrace();
}
StringRequest request = new StringRequest(Request.Method.POST, GET_NEWS, new Response.Listener<JSONObject>() {
@Override
public void onResponse(String response) {
Log.i(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + getMessage(error, context));
Toast.makeText(context, getMessage(error, context), Toast.LENGTH_SHORT).show();
}
}) …Run Code Online (Sandbox Code Playgroud) 我开始使用Retrofit,但我坚持这个简单的步骤.我有一个登录表单,我正在尝试使用服务器进行身份验证,但我无法发送请求.
这就是我尝试过的:
我的改造客户:
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create());
public static <S> S createService(Class<S> serviceClass) {
Retrofit retrofit = builder.client(httpClient.build()).build();
return retrofit.create(serviceClass);
}
Run Code Online (Sandbox Code Playgroud)
我的登录界面:
public interface Login {
@POST(LOGIN)
Call<String> loginWithCredentials(@Body LoginCredentials data);
}
Run Code Online (Sandbox Code Playgroud)
LoginCredentials类:
public class LoginCredentials {
private String name;
private String pass;
public LoginCredentials(String name, String pass) {
this.name = name;
this.pass = pass;
}
}
Run Code Online (Sandbox Code Playgroud)
我称之为的部分:
@Override
public void onClick(View v) {
showProgress(true);
String username = …Run Code Online (Sandbox Code Playgroud) 我正在使用Android的绑定库,我试图在TextView上添加或删除边距,具体取决于布尔值.如果这是真的,我希望TextView在右边有一个边距,在左边没有边距,如果不是则相反.所有其他资源工作正常,但是当我编译代码时,我得到关于TextView上的边距的错误:无法找到参数类型为float的属性'android:layout_marginRight'的setter.
谁能发现错误?
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="comment" type="mx.com.corpogas.dataModels.FeedbackComment"/>
<import type="android.view.View"/>
</data>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@{comment.isMine ? @drawable/comment_background_white : @drawable/comment_background_green}"
android:textSize="15sp"
android:textColor="@{comment.isSent ? (comment.isMine ? @color/colorPrimaryDark : @android:color/white) : @color/unsent_text}"
android:layout_marginRight="@{comment.isMine ? @dimen/feedback_comment_margin : @dimen/feedback_comment_no_margin}"
android:layout_marginLeft="@{comment.isMine ? @dimen/feedback_comment_no_margin : @dimen/feedback_comment_margin}"
android:text="@{comment.content}"/>
</layout>
Run Code Online (Sandbox Code Playgroud)
这是我的利润:
<dimen name="feedback_comment_margin">16dp</dimen>
<dimen name="feedback_comment_no_margin">0dp</dimen>
Run Code Online (Sandbox Code Playgroud)
当我删除边距时,程序编译并运行完美.
我正在展示一个DialogFragment.我实现它没有任何问题,直到我决定使用getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);.删除标题后,整个事情缩小.这是我的xml和类文件.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/red"
android:textSize="20sp"
android:text="@string/client_name_hint"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<ImageView
android:id="@+id/product_image"
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:textColor="@color/red"
android:textSize="30sp"
android:textStyle="bold"
android:text="$349.00"/>
<TextView
android:id="@+id/product_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="Color: White"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
android:background="#aaada9"
android:text="Text text text text text text text text text text text text text text text …Run Code Online (Sandbox Code Playgroud)