小编hat*_*ata的帖子

如何在Android Studio的现有文件中添加作者模板?

我要添加这个

/**
 * Created by cyborn on 1/10/15.
 */
Run Code Online (Sandbox Code Playgroud)

模板添加到Android Studio中现有的Java文件中。

java android android-studio

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

Python多处理池'raise ValueError("Pool not running") ValueError: Pool not running'函数带返回值

我正在尝试并行运行在循环中有返回值的函数。但它似乎停留在results = pool.map(algorithm_file.foo, population)for 循环的第二次迭代中

    raise ValueError("Pool not running")
ValueError: Pool not running
Run Code Online (Sandbox Code Playgroud)

示例代码:

from multiprocessing.dummy import Pool
import algorithm_file

population = [1, 3, 4]
pool = Pool(len(population))

total = list()

for _ in range(10):
    results = pool.map(algorithm_file.foo, population)
    pool.close()
    pool.join()
    total.append(sum(results))

print(total)
Run Code Online (Sandbox Code Playgroud)

里面的内容algorithm_file.py

from random import randint

def foo(x):
    return x * randint(0,5)
Run Code Online (Sandbox Code Playgroud)

我尝试放入pool = Pool(len(population))for 循环,但程序毫无例外地崩溃了。

我发现一些解决方案使用全局列表()。但无论如何,有没有办法维护具有返回值的函数呢?

Python 3.7.3

python return multiprocessing python-3.7

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

为什么Java中存在匿名类?

与普通类相比,匿名类中是否有任何特殊功能,因为我在这些类中没有看到任何特殊内容?

java lambda class anonymous-class

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

更新到API 23后获取java.lang.NoClassDefFoundError

我正在构建一个Android应用程序,当我中途使用SDK管理器更新我的SDK版本时,我还将Android Studio更新为1.3.2.执行此操作后,我的应用程序在某些设备上崩溃,但不是全部.

我得到的错误是

Process: com.pickingo.fe, PID: 11543
    java.lang.NoClassDefFoundError: android.support.v4.hardware.fingerprint.FingerprintManagerCompatApi23$1
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at com.activeandroid.ReflectionUtils.getModelClasses(ReflectionUtils.java:83)
            at com.activeandroid.DatabaseHelper.onCreate(DatabaseHelper.java:46)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
            at com.activeandroid.Registry.openDatabase(Registry.java:149)
            at com.activeandroid.Registry.initialize(Registry.java:107)
            at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:8)
            at com.pickingo.fe.Application.onCreate(Application.java:25)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1034)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4605)
            at android.app.ActivityThread.access$1500(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Run Code Online (Sandbox Code Playgroud)

这是我的Application.java类

import android.content.Context;

import com.activeandroid.ActiveAndroid;
import com.pickingo.fe.notification.NotificationManager;
import com.pickingo.fe.preference.PreferenceManager;
import com.pickingo.fe.sync.ServerUpdatePusher;
import com.pickingo.fe.test.StoreLogcat;

public class Application extends android.app.Application {


    public static boolean init = true;

    public static …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-gradle-plugin android-6.0-marshmallow

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

状态栏下方的导航抽屉

如下图所示,导航抽屉中有四个项目。第一个隐藏在状态栏下。我想要它在工具栏的下方(汉堡图标的下方)。如果我尝试移动代码中的任何内容,那么我的折叠工具栏就会混乱,或者所有内容都固定在顶部。有什么帮助吗?这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:fitsSystemWindows="true">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="48dp"
                    app:expandedTitleMarginEnd="64dp"
                    android:fitsSystemWindows="true">

                    <ImageView
                        android:src="@drawable/nerdz_main_page"
                        android:id="@+id/image"
                        android:layout_width="match_parent"
                        android:layout_height="400dp"
                        android:scaleType="fitXY"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax"/>

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:layout_collapseMode="pin" />

                </android.support.design.widget.CollapsingToolbarLayout>
            </android.support.design.widget.AppBarLayout>

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="24dp"
                        app:cardElevation="5dp"
                        android:text="this is a sample card "
                        app:cardUseCompatPadding="true">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/title"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

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

当我在 Android Studio 的 gradle 中添加 viewBinding 时,出现错误

我使用的是 Android Studio 4.0.1 版。

当我添加 viewBinding 时,出现错误。

在 gradle 中添加 viewBinding 时出错。

buildFeatures {
    viewBinding = true
}
Run Code Online (Sandbox Code Playgroud)

build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 5
        versionName "1.2.0"
        resValue("string", "growingio_project_id", "8979dc98cc52320f")
        resValue("string", "growingio_url_scheme", "growing.1f3e3791e1d6aee5")
    }
    compileOptions {
        sourceCompatibility rootProject.ext.sourceCompatibilityVersion
        targetCompatibility rootProject.ext.targetCompatibilityVersion
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: "*.jar")
    implementation …
Run Code Online (Sandbox Code Playgroud)

android android-gradle-plugin android-viewbinding

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

如何使 TextView 在片段中可滚动?

我在活动中创建了片段。每个片段都有一个文本视图。我想让片段内的所有文本视图都可以滚动。下面是我的 xml 和 java 代码。提前致谢

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".chemistry.AtomicNumber">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/atomicNumberDefinition"
            android:text="The atomic number..... "
            android:textAlignment="center"
            android:textColor="#000000"
            android:textSize="24sp"
            android:scrollbars="vertical" />
Run Code Online (Sandbox Code Playgroud)

Java代码:

public class AtomicNumber extends Fragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    public AtomicNumber() {
    }

    public static AtomicNumber newInstance(String param1, String param2) {
        AtomicNumber fragment = new AtomicNumber();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args); …
Run Code Online (Sandbox Code Playgroud)

android textview android-fragments android-scroll

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

模拟器屏幕看起来不同

AVDAPI 23那个做了一个,nexus 4它看起来像这样

在此处输入图片说明

Buttons & Manu在单独的面板中不是这样。

在此处输入图片说明

所以,我想知道是否Android Studio提供模拟器屏幕作为原始物理设备?而不是上面的第二张图片?或者我的emulator. 为什么我的emulator没有额外的面板buttons

请指导我。

android android-virtual-device android-emulator android-screen android-studio

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

为什么 Android viewModels() 扩展函数在fragment-ktx而不是viewmodel-ktx库中可用?

viewModels()当我如下使用时

class MainActivity : AppCompatActivity() {

    private val viewModel: MainViewModel by viewModels()

    // ... more codes
}
Run Code Online (Sandbox Code Playgroud)

为什么它可以在

implementation 'androidx.fragment:fragment-ktx:1.3.0'
Run Code Online (Sandbox Code Playgroud)

相反,当我包含如下内容时,它们在其中不可用?

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
Run Code Online (Sandbox Code Playgroud)

我以为它应该在viewmodel-ktx图书馆而不是fragment-ktx图书馆

android kotlin android-gradle-plugin android-viewmodel

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

如何上传PDF文件到服务器

我正在尝试将 PDF 文件上传到我的服务器。我可以使用位图上传图像解码。我正在重复使用相同的代码,但我需要在我的 Android 应用程序上上传用户的 PDF。

private void chooseFile(int type2) {
    //System.out.println(type2);
    Intent intent = new Intent();
    //intent.setType("application/pdf");
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),type2 );
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    //  System.out.println(data);
    if ((requestCode == 1 || requestCode == 2 || requestCode == 3 || requestCode == 4 || requestCode == 5 || requestCode == 6 || requestCode == 7 || requestCode == 8) && resultCode == RESULT_OK && data != …
Run Code Online (Sandbox Code Playgroud)

pdf android

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

replaceAll不能正常使用字符串

我得到了意外的结果......

 String s1 = "all"; 
 System.out.println(s1.replaceAll("$", "#"));
Run Code Online (Sandbox Code Playgroud)

即没有替换,如果没有$则无需替换,但为什么JVM添加'#'.o/p:所有#

java regex ng-options

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

如何解决java中预期的错误:“)”?

当我运行程序时,它说存在一些关于“)”的错误。我知道它的意思,但我不知道如何纠正它。以下代码是关于我的编程,请帮助我...谢谢!

import java.util.Scanner;
    public class Ex1_3 {
    public static void main(String args[]) {
  
     Scanner in = new Scanner(System.in);
     double kg = in.nextDouble();
     double m = in.nextDouble();
     double bmi = kg/(Math.pow(m,2));

     if (bmi < 18.5) {
        system.out.println("%1.2f kg, %1.2f m, BMI = %1.2f", kg, m, bmi "(underweight)");
     } else if (18.5 <= bmi < 25) {
        system.out.println("%1.2f kg, %1.2f m, BMI = %1.2f", kg, m, bmi "(normal)");  
     } else if (25 <= bmi < 30) {
        system.out.println("%1.2f kg, %1.2f m, BMI …
Run Code Online (Sandbox Code Playgroud)

java

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

Android gradle插件更新至7.0版本

我想更新到 android gradle 插件 7.0。有什么方法可以测试我需要在项目或代码中进行哪些更改?android studio 有没有预览工具?

android gradle android-studio android-gradle-plugin android-gradle-7.0

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