小编Ola*_*röm的帖子

Android Studio 错误“安装失败,原因是:‘连接被拒绝:连接’”

我正在尝试安装该应用程序,但 Android Studio 显示错误:

Launching 'app' on Xiaomi Redmi 4A.
Installation did not succeed.
The application could not be installed.
...
Installation failed due to: 'Connection refused: connect'
Run Code Online (Sandbox Code Playgroud)

我该如何修复这个错误?

connection android launch android-emulator android-studio

10
推荐指数
2
解决办法
2万
查看次数

更改 Visual Studio 2022 中的默认缩进

如何更改 Visual Studio 中的默认缩进?

我希望它始终使用制表符而不是空格。

在我看过的所有地方,它要么没有告诉我如何将选项卡设置为默认选项,要么已经过时了好几年。

编辑:
有点尴尬,我已经解决了问题。右下角的小部件仍然表示它正在使用空格,尽管它使用的是制表符。当我发现这些设置时,我感到非常沮丧,所以我没有测试它们是否有效(尽管右下角的小部件不会更新对我来说有点奇怪)。

c# indentation visual-studio visual-studio-2022

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

错误:使用未声明的类型 BindableObject

我正在关注 SwiftUI 放大应用程序的本教程,在创建符合 Bindable 对象的最终类时遇到此错误。

Error:Use of undeclared type 'BindableObject'

import Combine  
import SwiftUI  
import AWSAppSync  

final class TalkStore: BindableObject {
/*
    Required by SwiftUI
*/
    let didChange = PassthroughSubject<TalkStore, Never>()
    var listTalks: [ListTodosQuery.Data.ListTodo.Item] {
        didSet {
            didChange.send(self)
        }
    }

    //We will be using this later.
    private let appSyncClient: AWSAppSyncClient!

/*
    Init if running app is using SwiftUI Content View
*/
    init(talks: [ListTodosQuery.Data.ListTodo.Item]) {
        self.appSyncClient = nil
        self.listTalks = talks
    }
}
Run Code Online (Sandbox Code Playgroud)

苹果是否有可能更改了类名?
我怎么知道?

ios swift aws-amplify swiftui

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

如何使文本按钮自动调整大小以适合按钮

如何使按钮文本自动调整其大小以适合按钮?

我尝试过设置:

android:autoSizeTextType="uniform"
Run Code Online (Sandbox Code Playgroud)

但这行不通。
如果我输入以下内容,文本仍然以两行结束:

android:maxLines="1"
Run Code Online (Sandbox Code Playgroud)

文本的某些部分消失了。

是否有任何方法(以编程方式或在 XML 中)自动调整文本大小以适合一行上的按钮,并且还显示整个文本?

编辑 :

这是我的 XML,我想要放入文本的按钮是“btnReq”和“btnAcc”:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".PlayFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        app:layout_constraintBottom_toTopOf="@+id/tableLayout"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.074"
        tools:layout_editor_absoluteX="0dp">

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:paddingRight="10dp">

            <EditText
                android:id="@+id/et_email"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:ems="10"
                android:hint="email"
                android:inputType="textPersonName"
                android:autoSizeTextType="uniform"/>

            <Button
                android:id="@+id/btnReq"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="REQUEST"
                android:autoSizeTextType="uniform"
                android:maxLines="1"/>

            <Button
                android:id="@+id/btnAcc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="ACCEPT"
                android:autoSizeTextType="uniform"
                android:maxLines="1"/>
        </LinearLayout>
    </LinearLayout>

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerInParent="true"
        android:padding="10dp"
        app:layout_constrainedHeight="false"
        app:layout_constraintBottom_toBottomOf="parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-button kotlin android-studio

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

如何在Android中逐像素显示位图?

我正在尝试逐像素显示位图图像(这明确意味着有一些延迟)。
为此,我使用两个“for 循环”,但它只打印单行像素......

我的代码:

Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //Toast.makeText(getBaseContext(), "Printing...", Toast.LENGTH_SHORT).show();
        iImageArray = new int[bMap.getWidth()* bMap.getHeight()];                                   //initializing the array for the image size
        bMap.getPixels(iImageArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());   //copy pixel data from the Bitmap into the 'intArray' array  
             
        //Canvas canvas = new Canvas (bMap);
        //replace the red pixels with yellow ones  
        for (int i=0; i < bMap.getHeight(); i++) {  
            for(int j=0; j<bMap.getWidth(); j++) {
                iImageArray[j] = 0xFFFFFFFF;
            } …
Run Code Online (Sandbox Code Playgroud)

android image pixel bitmap

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

蓝牙串行端口通信 (SPP)

我们正在开发一个通过蓝牙使用 SPP(串行端口配置文件)的应用程序,开发人员正在讨论使用某种类型的协议和数据包传输,还是仅在没有任何形式的 ACK、序列或大小信息的情况下流式传输数据。

蓝牙是否提供有保证的传输和数据完整性,以便我们不需要数据包协议设计的开销?

我们可以仅依靠蓝牙来确保数据传输吗?

protocols bluetooth transmission data-integrity spp

6
推荐指数
2
解决办法
4588
查看次数

如何仅使用MSPaint和Visual Studio为Visual Studio创建图标

我已经阅读了很多有关创建图标,然后在Visual Studio项目->属性->图标和清单中分配这些图标之一的文章。这样做时,我收到一条消息,指出该图标无效。我一直这样做的主要方式是使用MSPaint。

这是当我在MSPaint中保存一个24位图标时,在我读过的一篇文章中提到了这一点。我在Visual Studio 2012的图像编辑器中找不到任何编辑功能。那么,如何为应用程序创建一个简单的图标?

我知道那里有免费的转换器。我特别在问是否有一种方法可以使用现有工具(如Visual Studio,MSPaint等)进行转换。

icons image-editor visual-studio visual-studio-2012 visual-studio-2017

6
推荐指数
2
解决办法
5980
查看次数

Android库中的getAssets()方法不起作用

作为 Android 编程的新手,我已将四个文件附加到我的库的资产文件夹中。
您可以看到附图。

图书馆

我想使用下面的代码通过 Android 库访问这些文件(如果我不在 Android 库中使用此代码,则当我在 MainActivity 中使用它时,它运行时不会出现错误)。

public void copy_weights() {
    try {
        AssetManager assetFiles = getAssets();
        String[] files = assetFiles.list("");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();  //catch the error in this line
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

但这段代码给了我错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.Context.getAssets' on a null object refrence

我尝试了其他方法,例如直接访问home:///android_asset/7.cfg,但也无法访问文件。

编辑1

我像下面这样copy_weights()调用mainActivity

public class MainActivity extends AppCompatActivity {
@Override …
Run Code Online (Sandbox Code Playgroud)

java android android-assets

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

如何在单个R会话中创建多个临时目录?

我需要在单个R会话中创建多个临时目录,但是每次调用tempdir()时,我都会得到相同的目录。

有没有一种简单的方法来确保每个呼叫都会给我一个新的临时目录?

r temp

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

Java,使用 Scanner 尝试捕获

我正在创建一个小算法,这是其中的一部分。

如果用户输入非整数值,我想输出一条消息并让用户再次输入一个数字:

boolean wenttocatch;

do 
{
    try 
    {
        wenttocatch = false;
        number_of_rigons = sc.nextInt(); // sc is an object of scanner class 
    } 
    catch (Exception e) 
    {
        wenttocatch=true;
        System.out.println("xx");
    }
} while (wenttocatch==true);
Run Code Online (Sandbox Code Playgroud)

我得到了一个永无止境的循环,我不知道为什么。

如何识别用户是否输入了一些非整数?
如果用户输入一个非整数,我如何要求用户再次输入?

更新
当我打印异常时,我收到“InputMismatchException”,我该怎么办?

java input try-catch java.util.scanner inputmismatchexception

5
推荐指数
2
解决办法
2万
查看次数