小编abr*_*sze的帖子

MalformedJsonException:使用JsonReader.setLenient(true)在第1行第1列路径接受格式错误的JSON

尝试使用Retrofit以JSON格式发送信息,但它进入Retrofit的onFailure方法,并引发以下错误:

com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经尝试通过使用以下链接的答案来解决此问题:1)带Retrofit API的MalformedJsonException? 2)使用JsonReader.setLenient(true)在第1行第1列路径$接受格式错误的JSON

这是我的代码:

改造界面:

public interface ServerApi {
    @POST("/register/test")
    Call<User> createAccount(@Body User user);
}
Run Code Online (Sandbox Code Playgroud)

MainActivity与连接的东西:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        User user= new User("myemail@mail.ru","vercode100");
        sendNetworkRequest(user);
    }

    private void sendNetworkRequest(User user){

        //create Retrofit instance
        Retrofit.Builder builder= new Retrofit.Builder()
                .baseUrl("http://localhost:8080")
                .addConverterFactory(GsonConverterFactory.create());

        Retrofit retrofit= builder.build();

        //Get client and call object for the request …
Run Code Online (Sandbox Code Playgroud)

android json gson retrofit retrofit2

5
推荐指数
1
解决办法
8964
查看次数

RCConnection错误:setSDP错误:无法设置远程提供sip:使用SDP调用而不使用DTLS指纹

我正在使用Restcomm的Android SDK并尝试将其配置到我们的服务器,但收到以下错误:

RCConnection Error: setSDP Error: Failed to set remote offer sip: Called with SDP without DTLS fingerprint
Run Code Online (Sandbox Code Playgroud)

但是,当我改回Restcomm服务器时,它工作正常.

我试图在Google和Git上搜索它,但那里提供的解决方案没有帮助.知道如何解决这个问题(请详细解释,因为我是WebRTC的新成员)?

编辑:

如果我从移动设备呼叫到网络或从网络呼叫到网络,它可以正常工作.仅当移动设备尝试接受呼叫时才会出现此问题.

android dtls webrtc restcomm

5
推荐指数
1
解决办法
378
查看次数

java.security.InvalidKeyException:密钥库操作失败

我得到java.security.InvalidKeyException: Keystore operation failed. 有没有人有想法?这是我的代码:

initDecodeCipher 的代码:

private static void initDecodeCipher(int mode) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException, InvalidKeyException, NoSuchPaddingException {

    KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) sKeyStore.getEntry(FINGERPRINT_KEY_NAME, null);
    Cipher output = Cipher.getInstance(TRANSFORMATION);
    output.init(Cipher.DECRYPT_MODE, privateKeyEntry.getPrivateKey());
}
Run Code Online (Sandbox Code Playgroud)

initEncodeCipher 的代码:

private static void initEncodeCipher(int mode) throws KeyStoreException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException {
    PublicKey key = sKeyStore.getCertificate(FINGERPRINT_KEY_NAME).getPublicKey();

    PublicKey unrestricted = KeyFactory.getInstance(key.getAlgorithm()).generatePublic(new X509EncodedKeySpec(key.getEncoded()));
    OAEPParameterSpec spec = new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT);

    sCipher.init(mode, unrestricted, spec);
}
Run Code Online (Sandbox Code Playgroud)

生成新密钥的代码:

@TargetApi(Build.VERSION_CODES.M)
private static boolean generateNewKey() {

    if (getKeyPairGenerator()) {

        try …
Run Code Online (Sandbox Code Playgroud)

java encryption android cryptography keystore

3
推荐指数
1
解决办法
2461
查看次数

int a之间的区别; int b; 和int a,b.(尊重内存管理)

我知道,无论int a; int b;int a, b;正在做的一样.但我想知道int a, b;在编译期间使用的内存少于int a; int b;.我的意思是他们之间有什么区别吗?

java memory memory-management

1
推荐指数
2
解决办法
1153
查看次数

Bitmap.compress 花费太多时间(约 2 秒)

位图压缩过程需要太多时间。我该如何解决这个问题?

在活动中:

icon= BitmapFactory.decodeResource(getResources(),R.mipmap.image);
Run Code Online (Sandbox Code Playgroud)

在回调类中:

        synchronized (holder) {
            stream = new ByteArrayOutputStream();
            Log.d("LIFE_CYCLE", "settingImage 1=" + System.currentTimeMillis());
            icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
            Log.d("LIFE_CYCLE", "settingImage 2=" + System.currentTimeMillis());
            byteArray = stream.toByteArray();
            b = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
            if(mWidth<mHeight){
                icon= Bitmap.createScaledBitmap(b, (int)(mWidth*0.75), (int)(mWidth*0.75), false);
            }
            else{
                icon= Bitmap.createScaledBitmap(b, (int)(mHeight*0.75), (int)(mHeight*0.75), false);
            }

            canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
            canvas.drawBitmap(icon, ((mWidth)-icon.getWidth())/2, (mHeight-icon.getHeight())/2, new Paint());
            draw_target(canvas);
        }
Run Code Online (Sandbox Code Playgroud)

此行大约需要 2 秒:

icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
Run Code Online (Sandbox Code Playgroud)

PS我的图像是部分透明的,所以我需要使用.PNG而不是.JPG

android bitmap bitmapimage bitmapfactory android-bitmap

1
推荐指数
1
解决办法
1497
查看次数

多按钮初始化

我有10个按钮,我想通过调用一个方法来初始化它们。我的意思是现在我有很多:

button= (Button) findViewById(R.id.button);
button1= (Button) findViewById(R.id.button1);
Run Code Online (Sandbox Code Playgroud)

我想要一个这样的方法,并在每次按钮初始化时调用它:

private void initialize(Button mybutton){
  mybutton= (Button) findViewById(R.id.mybutton);
}
Run Code Online (Sandbox Code Playgroud)

android button findviewbyid

-1
推荐指数
1
解决办法
125
查看次数

如何始终显示软键盘并且不让它关闭?

我想知道 2 件事

  1. 如何始终显示软键盘并且不让它关闭(即使按下后退或确定按钮)?

  2. 我怎样才能从中获得输入?

我已经尝试过这段代码:

    EditText yourEditText= (EditText) findViewById(R.id.ed);
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Run Code Online (Sandbox Code Playgroud)

具有这些变体:

  1. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
  2. imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
  3. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

keyboard android android-keypad android-edittext window-soft-input-mode

-2
推荐指数
1
解决办法
4224
查看次数