编辑:
现在应用程序正在运行.但它只是在第一次启动后(安装后)请求许可.如果我离开应用程序(按下后退按钮),然后再启动它,它不会要求许可.为什么会这样?
不按后退按钮会通过调用onDestroy()来破坏活动,不应再次调用onCreate()方法吗?
原始问题
我的应用程序允许用户在按下按钮时找到他们当前的位置.每当应用程序第一次启动时,它会询问用户权限,但在授予权限时崩溃会发出以下错误:
java.lang.RuntimeException: Failure delivering result
ResultInfo{who=@android:requestPermissions:, request=10, result=-1,
data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has
extras) }} to activity
{com.example.hpi5.location/com.example.hpi5.location.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.Button.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
Run Code Online (Sandbox Code Playgroud)
以下是我的活动代码:
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.content.pm.PackageManager;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button ;
LocationListener locationListener;
LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud) 我做了一个蓝牙应用程序.在它工作正常Nougat,Marshmallow,Jelly Bean,KitKat但对于原因,在Android的崩溃Lollipop,当Discover按钮被点击(其中发现的所有发现的设备).
这是在点击Discover按钮上触发的方法-
private void discoverDevices() {
Log.d(TAG, "btnDiscover: Looking for unpaired devices.");
if(mBluetoothAdapter.isDiscovering()){
mBluetoothAdapter.cancelDiscovery();
Log.d(TAG, "btnDiscover: Canceling discovery.");
//check BT permissions in manifest
checkBTPermissions();
mBluetoothAdapter.startDiscovery();
IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
}
if(!mBluetoothAdapter.isDiscovering()){
//check BT permissions in manifest
checkBTPermissions();
mBluetoothAdapter.startDiscovery();
IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
}
}
Run Code Online (Sandbox Code Playgroud)
CheckBTPermissions() -
private void checkBTPermissions() {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP){
int permissionCheck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
permissionCheck += …Run Code Online (Sandbox Code Playgroud) *commit N+20 <-- (HEAD)branch fb/abc(i made 20 commits in this branch) [most recent]
.
.
*commit N <-- branch dev-abc, origin/dev-abc //created another feature branch from here "fb/abc"
.
.
Run Code Online (Sandbox Code Playgroud)
然后我运行了以下命令:
git checkout dev-abc
get merge fb/abc
Run Code Online (Sandbox Code Playgroud)
没有对 dev-abc 分支进行任何其他更改。所以这是一个简单的快进合并。
此时,图表如下所示。
*commit N+20 <-- branch fb/abc, dev-abc(HEAD) [most recent]
.
.
*commit N <-- origin/dev-abc
.
.
Run Code Online (Sandbox Code Playgroud)
现在,我将所有这些更改推送到远程
此时,在创建拉取请求时,我在其中一个文件中遇到了合并冲突。(为什么??)
无论如何,我在 GitHub 冲突解决程序本身中解决了所有冲突。这在 GitHub 中创建了一个新的提交,该提交不存在于我的本地副本中。我需要更改此提交的提交消息。我怎样才能做到这一点?
还有一件事,我在本地进行了两次尚未推送的额外提交。每当我尝试推送时,我都会收到一条错误消息,指出我在远程进行了一些本地不存在的更改。它建议我git pull首先进行这些更改(我认为这是在 GitHub 上创建的附加提交(我想更改其消息))。
*commit N+22 <-- branch dev-abc(HEAD) [most recent] // how the …Run Code Online (Sandbox Code Playgroud) 运行以下命令时出现错误:
docker run --name freeipa-server-container -ti \
-h ipa.example.test \
--read-only \
-v /var/lib/ipa-data:/data:Z freeipa-server [ opts ]
Run Code Online (Sandbox Code Playgroud)
错误:
systemd 239 在系统模式下运行。(+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=legacy)
检测到虚拟化容器-其他。
检测到架构 x86-64。将主机名设置为
<ipa.example.test>.从随机生成器初始化机器 ID。
无法移动剩余的用户空间进程,忽略:输入/输出错误
2020 年 3 月 22 日星期日 16:47:43 UTC /usr/sbin/ipa-server-configure-first
内核中启用了 IPv6 堆栈,但没有分配 ::1 地址的接口。将 ::1 地址解析添加到“lo”接口。您可能需要在 sysctl.conf 中的接口“lo”上启用 IPv6。ipa-server-install 命令失败。有关详细信息,请参阅 /var/log/ipaserver-install.log
最后一部分说我需要在 sysctl.conf 中的接口“lo”上启用 IPv6。
这是 的输出ifconfig。它已经启用。不是吗? …
我的游戏场景中有一个多维数据集(播放器)。我已经编写了一个C#脚本来约束Mathf.Clamp()Cube 的移动(使用),因此它不会离开屏幕。
下面是我FixedUpdate()的脚本方法
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3(
Mathf.Clamp (rb.position.x, x_min, x_max),
0.5f,
Mathf.Clamp(rb.position.z, z_min, z_max)
);
}
Run Code Online (Sandbox Code Playgroud)
的值x_min,x_max,z_min,z_max是-3,3,-2,8分别经由统一检查员输入。
问题
脚本运行良好,但我的播放器(多维数据集)可以负向最多移动-3.1个单位X-AXIS(如果我一直按住左箭头按钮),负向可以最多移动0.1个单位X-AXIS(此行为也适用于其他轴)。当我停止按下按钮时,它显然会夹紧-3.1到-3。
Mathf.Clamp()首先将多维数据集限制为-3个单位?我的场景中有一个立方体(播放器)和一个平面(地板)。两者都已Colliders附加到它们,并且有一个RigidBody仅附加到Cube的组件。Cube位于Plane上方。
Cube附有一个脚本,用于查找碰撞。
private void OnCollisionEnter(Collision collision)
{
Debug.Log("...........................Collision");
}
Run Code Online (Sandbox Code Playgroud)
问题:
当平面和立方体碰撞时,消息会打印两次。
...........................碰撞
UnityEngine.Debug:Log(Object) jump:OnCollisionEnter(Collision)(在 Assets/jump.cs:34)
...........................碰撞
UnityEngine.Debug:Log(Object) jump:OnCollisionEnter(Collision)(在 Assets/jump.cs:34)
为什么会这样?碰撞是否发生两次?
我的游戏场景中有一个球(球体)和一个地板。Ball.cs附着在球上以控制其在游戏中的移动(球仅在垂直方向移动)。Ball 和 floor 都附有对撞机,每当球接触地板时,理想情况下游戏应该结束。
Ball.cs脚本中的OnCollisionEnter2D方法。
private void OnCollisionEnter2D(Collision2D collision)
{
// Zero out the ball's velocity
rb2d.velocity = Vector2.zero;
// If the ball collides with something set it to dead...
isDead = true;
//...and tell the game control about it.
GameController.instance.PlayerDied();
}
Run Code Online (Sandbox Code Playgroud)
更新功能
void Update () {
//Don't allow control if the bird has died.
if (isDead == false)
{
//Look for input to trigger a "flap".
if (Input.GetMouseButtonDown(0))
{
//...zero out the birds …Run Code Online (Sandbox Code Playgroud)