如何使用 GPS 在 Android 中获取我的当前位置?

2023-12-01

我想通过 GPS 以地址形式获取我当前的位置。我正在使用android studio。 它说我的应用程序停止工作。 其中有什么错误呢? 有人可以帮我摆脱这个困境吗?

我在 Activity_main.xml 文件中的代码是

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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=".MainActivity">

<TextView
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

我在 MainActivity.java 中的代码是

package com.example.showlatlong;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

import java.util.List;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

Location gps_loc, network_loc, final_loc;
double longitude;
double latitude;
String userCountry, userAddress;


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

    TextView tv = findViewById(R.id.text_view);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) {

        return;
    }

    try {
        gps_loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        network_loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (gps_loc != null) {
        final_loc = gps_loc;
        latitude = final_loc.getLatitude();
        longitude = final_loc.getLongitude();
    }
    else if (network_loc != null) {
        final_loc = network_loc;
        latitude = final_loc.getLatitude();
        longitude = final_loc.getLongitude();
    }
    else {
        latitude = 0.0;
        longitude = 0.0;
    }

     ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_NETWORK_STATE}, 1);



    try {

        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        if (addresses != null && addresses.size() > 0) {
            userCountry = addresses.get(0).getCountryName();
            userAddress = addresses.get(0).getAddressLine(0);
            tv.setText(userCountry + ", " + userAddress);
        }
        else {
            userCountry = "Unknown";
            tv.setText(userCountry);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

我在manifest.xml中的代码是

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

整个代码是这样的。它正在打开应用程序,不到一秒钟,它就会通过在我的 Android 应用程序上抛出“应用程序不断停止”的错误消息来关闭。 这是我在 logcat 中得到的

2019-09-11 12:58:45.344 15400-15400/com.example.showlatlong E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.showlatlong, PID: 15400
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.showlatlong/com.example.showlatlong.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6238)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
 Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.showlatlong-1/base.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.showlatlong-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.showlatlong-1/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
    at com.example.showlatlong.MainActivity.onCreate(MainActivity.java:29)
    at android.app.Activity.performCreate(Activity.java:6857)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2676)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6238)
    at java.lang.reflect.Method.invoke(Native Method)
    at 


 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit. 
 java:933)
 2019-09-11 12:58:45.344 15400-15400/com.example.showlatlong  
 E/AndroidRuntime:     
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

在 AndroidManifest.xml 中,您必须将其放在应用程序标记的上方或下方。

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

因为你没有显示你的代码你一直在做什么,所以我不知道如何解决你的问题。但下面的代码是我在应用程序中用于获取当前用户所在国家/地区的代码。

活动_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">

    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

MainActivity.java

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.List;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

        Location gps_loc;
        Location network_loc;
        Location final_loc;
        double longitude;
        double latitude;
        String userCountry, userAddress;

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


        TextView tv = findViewById(R.id.text_view);

        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) {

            return;
        }

        try {

            gps_loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            network_loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

        } catch (Exception e) {
            e.printStackTrace();
        }

        if (gps_loc != null) {
            final_loc = gps_loc;
            latitude = final_loc.getLatitude();
            longitude = final_loc.getLongitude();
        }
        else if (network_loc != null) {
            final_loc = network_loc;
            latitude = final_loc.getLatitude();
            longitude = final_loc.getLongitude();
        }
        else {
            latitude = 0.0;
            longitude = 0.0;
        }


        ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_NETWORK_STATE}, 1);

        try {

            Geocoder geocoder = new Geocoder(this, Locale.getDefault());
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            if (addresses != null && addresses.size() > 0) {
                userCountry = addresses.get(0).getCountryName();
                userAddress = addresses.get(0).getAddressLine(0);
                tv.setText(userCountry + ", " + userAddress);
            }
            else {
                userCountry = "Unknown";
                tv.setText(userCountry);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你不得不理解这段代码。另一件事是,如果您在模拟器上运行应用程序,它将继续显示“美国”或更具体地说,Googleplex 的位置。只需在真实设备上运行它即可返回您当前的位置。

要返回您当前的位置而不仅仅是国家/地区本身,您可以替换

地址.get(0).getCountryName()

与类似的东西

地址.get(0).getPostalCode()

or

地址.get(0).getAdminArea()

等等。

您也可以将这些值连接为字符串以详细显示您当前的位置。

请看一下this

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 GPS 在 Android 中获取我的当前位置? 的相关文章

  • 合并两个位图图像(并排)

    任何人都可以帮助将两个位图图像合并为单个位图 在android中 并排 谢谢 尤瓦拉吉 您可以使用Canvas 查看这篇文章 http www jondev net articles Combining 2 Images in Androi
  • 如何从另一个xml文件动态更新xml文件?

    我想从另一个 xml 文件更新 xml 文件 我使用了一个 xml 文件 如下所示 one xml
  • 无法合并 Dex - Android Studio 3.0

    当我在稳定频道中将 Android Studio 更新到 3 0 并运行该项目时 我开始收到以下错误 Error Execution failed for task app transformDexArchiveWithExternalLi
  • MI设备中即使应用程序被杀死,如何运行后台服务

    您好 我正在使用 alaram 管理器运行后台服务 它工作正常 但对于某些 mi 设备 后台服务无法工作 我使用了服务 但它无法工作 如何在 mi 中运行我的后台服务 MI UI有自己的安全选项 所以你需要的不仅仅是上面提到的粘性服务 你需
  • 将标题设置为操作栏时出现空指针异常

    Error Caused by java lang NullPointerException Attempt to invoke virtual method void android app ActionBar setTitle java
  • 如何在照片删除后刷新 Android 的 MediaStore

    问题 如何使媒体存储刷新其已删除文件的条目 从外部存储中删除代码中的照片后 我仍然在图库中看到已删除照片的插槽 空白照片 画廊似乎反映了媒体存储 并且在媒体存储中找到了已删除的照片 直到手机重新启动或通常 直到重新扫描媒体为止 尝试扫描已删
  • 下载图像并显示它

    应用程序的主要目的是下载和显示图像 但是当我尝试启动应用程序时它崩溃了 这是我的代码 private DownloadImageTask task protected void onCreate Bundle savedInstanceSt
  • Android 手机应用意图

    我想在手机上启动手机应用程序作为意图 我正在使用这个代码 startActivity getPackageManager getLaunchIntentForPackage com android phone 但该函数抛出一个空指针异常 因
  • 如何检测 Google Play 上是否有我的应用程序的更新? [复制]

    这个问题在这里已经有答案了 有没有办法以编程方式检查 Google Play 上我的应用程序是否有更新 以便通知用户 我知道 android google play 有自动通知 但我想使用我自己的通知 弹出消息来更新可用性 有点像 Vibe
  • Python Kivy - 在本机网络浏览器中打开 url 的应用程序

    我尝试制作一个简单的应用程序 在单击 Screen One 上的按钮后 在 Kivy 中打开一个网页 我使用了这个主题 Python 在应用程序中直接显示网络浏览器 iframe https stackoverflow com questi
  • 我们可以在 android studio 中拥有没有 app 文件夹的项目,并将所有内容(java/res/etc)放在根目录中吗

    我想知道在 Android studio 中是否可以有没有应用程序模块 应用程序或任何其他名称 的 android 项目 意味着我可以在项目本身的根目录中创建包和资源 而不是使用应用程序模块 编辑 结构看起来像 MyApp idea gra
  • 在 Android 中使用 iText 读取或打开 PDF 文件

    我是 Android 应用程序开发新手 使用 iText 我完成了 PDF 创建并在创建的文件上写入 现在我想阅读该 PDF 文件 如何使用 iText 打开或阅读 PDF 文件 例子将是可观的 那么提前 哪个是渲染 PDF 文件的最佳库
  • 当应用程序未运行时如何堆叠 Firebase Cloud Messaging 通知?

    我在用Firebase Cloud Messaging将推送通知从我的服务器发送到我的 Android 应用程序 当应用程序运行时 通知是stacked因为我将它们设置为我的一个组FirebaseMessagingService 这很好 但
  • 有没有办法在Android上创建一个三角形按钮?

    有没有办法创建一个三角形的按钮 我知道我可以将三角形图像作为背景 但这将使三角形之外的区域可单击 有没有办法固定按钮角 X 和 Y 以便我可以将其变成三角形 您可以覆盖OnTouch http developer android com r
  • Android:如何使视图增长以填充可用空间?

    这看起来很简单 但我不知道该怎么做 我有一个带有 EditText 和两个 ImageButtons 的水平布局 我希望 ImageButtons 具有固定大小 并且 EditText 占据布局中的剩余空间 如何才能做到这一点
  • 如何在android sdk上使用PowerMock

    我想为我的 android 项目编写一些单元测试和仪器测试 然而 我遇到了一个困扰我一段时间的问题 我需要模拟静态方法并伪造返回值来测试项目 经过一些论坛的调查 唯一的方法是使用PowerMock来模拟静态方法 这是我的 gradle 的一
  • ormlite 将日期读取为 'yyyy-MM-dd'

    我需要读取给我的 sqlite 数据库 因此我无法更改表中的日期格式 yyyy MM dd 当我尝试使用 ormlite 为我生成对象时 使用以下注释 DatabaseField columnName REVISION DATE dataT
  • OpenGL ES 2.0 屏幕闪烁

    我面临着一个大问题 我正在使用带有 Android 4 0 3 的 Transformer tf101 选项卡 我的应用程序使用自定义 OpenGL ES 2 0 表面 我正在用纹理渲染多个平面 该纹理大约发生变化 每秒 20 次 并通过传
  • Android:获取最新意图

    如何获取发送到活动的最后一个意图 的文档onNewIntent 建议我需要做这样的事情 class MyActivity public void onNewIntent Intent intent setIntent intent reac
  • 在 Android 中更新到 API 26 时,清单合并失败并出现多个错误

    我尝试使用 API 26 更新我的 gradle 安卓工作室2 3 3 但我在编译项目时遇到以下错误 这是我收到的错误的屏幕截图 应用级别build gradle Top level build file where you can add

随机推荐

  • 在 PHP 中动态访问类常量

    我希望能够动态查找常量的值 但使用变量不适用于语法 gives apple banana orange Fatal error Access to undeclared static property Food type 如何动态调用常量
  • 在 AppEngine Python 上使用 Reportlab 生成的 PDF 文档中添加图像文件的正确方法

    我正在尝试使用 App Engine Python 上的 reportlab 生成 PDF 报告 但我不知道如何正确附加图像 图像是静态的 这是我的项目的目录树 这就是我所做的 在 奇帕斯 py 获取图像 im Image static l
  • python脚本的CPU使用率

    是否可以检查简单脚本的CPU使用率 例如 如何获取打印 100 次 hello world 的 CPU 使用率 以百分比表示 目前我正在控制台中获取执行时间 方法是 time p python script py 如果你使用的是 UNIX
  • php 包含文件包含

    我正在一个网站上工作 并被要求包含位于我的 php 脚本上方的文件夹中的文件 问题是那些我被要求包含的 php 文件包含在其中 因此 在调用我的 php 页面时找不到它们引用的文件 处理这种情况的最佳方法是什么 将文件从文件夹 B 包含到文
  • 将客户端证书设置为 Java HTTP 连接中的请求属性?

    我有一个 Java 应用程序 它通过带有 SSL 的套接字连接到另一个 Java 应用程序 因此我的客户端 JVM 已经具有 Djavax net ssl keyStore and Djavax net ssl trustStore属性设置
  • 如何在延迟着色中从光照几何体的内部进行绘制

    我正在尝试使用 OpenGL 和 GLSL 实现延迟着色器 但我在处理光照几何时遇到了问题 这些是我正在采取的步骤 Bind multitarget framebuffer Render color position normal and
  • 访问 Service 中的请求范围 Bean

    我有一颗普通豆 它是 a Scope request 或 b 放置在HttpServletRequest通过过滤器 拦截器 如何在 a 中访问这个 bean Service哪一种是应用程序范围的单例 这样做的原因是 因为我有一个自定义对象R
  • 使用 Heroku 设置 Paperclip Amazon S3

    has attached file image storage gt s3 s3 credentials gt RAILS ROOT config s3 yml path gt style filename 我不知道什么 path gt s
  • 缺少 1 个必需的位置参数:'self'

    这是我的代码 class Email Stuff def init self self emailaddr None self recipaddr None self EmailUser None self EmailPass None d
  • 如何确定文本节点中被点击的字符?

    我可以设置一个事件侦听器来告诉我 HTML 文档中某个位置何时发生鼠标单击 但是 如果单击发生在某些文本上 我需要知道单击发生在文本中的哪个字符上 有没有办法做到这一点 我能想到一些非常令人讨厌的解决方案 例如 对于文档中的每个字符 我可以
  • HttpClient上传大文件并显示发送的字节数

    我找到了这个代码示例 import org apache http params CoreProtocolPNames import org apache http util EntityUtils public class PostFil
  • 从 Excel 将超过 65.535 行导入到 MS Access

    我正在运行以下代码将整个工作表从 Excel 导入到 Access 该工作表有 77k 行 但 Access 仅导入 65 535 行 关于如何修复它有任何疑问吗 Excel 和 Access 都是 2013 版本 Function imp
  • 为什么我们需要将 MDSYS.ST_GEOMETRY 视为 ST_LINESTRING 才能使用 ST_PointN(1)?

    MDSYS ST GEOMETRY 甲骨文18c 以下查询有效 它从 MDSYS ST GEOMETRY 中提取第一个点 Source https www spdba com au using oracles st geometry typ
  • 使用intel内联汇编器编码带有进位的bigint add

    我想做一个快速代码来添加大整数中的 64 位数字 uint64 t ans n uint64 t a n b n assume initialized values for int i 0 i lt n i ans i a i b i 但以
  • 在 webgl 片段着色器中按颜色计算像素

    我有 2d 纹理 S 并且想要返回 3d 纹理 H 这样像素 H r g b 等于纹理 S 中颜色 rgb 的像素数 基本上是纹理 S 中颜色的直方图 我知道遮挡查询 但它仅在 webgl2 中可用 而 IIUC 即使在那里也只能使用布尔结
  • Android SeekBar 拇指自定义

    我想隐藏栏 只想显示拇指 我用 max height 0dip 做到了 但它没有完全起作用 我还想在拇指上设置文本并使用多个图像创建拇指 例如 拇指按钮像图像一样并且具有文本 并且该按钮具有尾部下字 它随着行增量而增加 关于删除背景 我设法
  • 从 python 脚本获取 shell 脚本“读取”值

    外壳脚本 你好 sh bin bash echo Enter your name read name echo Hello name 我想从 python 中调用 Hello sh 并以非交互方式填充变量 name 如何做呢 不知道如何阅读
  • 在 Swift 中的 UITableViewController 之上添加一个 UIView

    我目前使用 UITableViewController PFQueryTableViewController 我想在 TableView 顶部显示一个 UIView 理想情况下 我想在故事板中执行此操作 这样我就可以轻松地向其中添加其他标签
  • nltk下载url授权问题

    我尝试使用 nltk download 更新我的 nltk 数据 但收到 HTTP 错误 401 需要授权 当我追踪有问题的网址时 我在 downloader py 中找到了它 DEFAULT URL http nltk googlecod
  • 如何使用 GPS 在 Android 中获取我的当前位置?

    我想通过 GPS 以地址形式获取我当前的位置 我正在使用android studio 它说我的应用程序停止工作 其中有什么错误呢 有人可以帮我摆脱这个困境吗 我在 Activity main xml 文件中的代码是