gpt4 book ai didi

java - Android Java 类中的非法类型 'void'

转载 作者:行者123 更新时间:2023-11-29 04:29:30 32 4
gpt4 key购买 nike

我在 Android Java 应用程序中遇到错误Illegal type 'void'

错误出现在 private void createFolder()public void onRequestPermissionsResult 代码块上。

我不知道是否缺少某些导入或 public class Berechtigungen extends AppCompatActivity 代码行有错误。

如果有人知道这个问题的答案,请写出来,谢谢。

我的代码:

package barsoftware.suedtirolpointer;

import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.Manifest;
import android.content.pm.PackageManager;


public class Berechtigungen extends AppCompatActivity {

final int REQ_CODE_EXTERNAL_STORAGE_PERMISSION = 45;

public void GPS() {
if(ActivityCompat.checkSelfPermission(Berechtigungen.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
// Anweisung
} else {
ActivityCompat.requestPermissions(Berechtigungen.this,new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQ_CODE_EXTERNAL_STORAGE_PERMISSION);
}
}
};


private void createFolder(){
File ordner = new File(Environment.getExternalStorageDirectory(), "TestOrdner");
ordner.mkdirs();
Toast.makeText(getApplicationContext(), "Ordner erstellt", Toast.LENGTH_SHORT).show();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if(requestCode == REQ_CODE_EXTERNAL_STORAGE_PERMISSION && grantResults.length >0 &&grantResults[0] == PackageManager.PERMISSION_GRANTED){
createFolder();
}
}
}

最佳答案

是语法错误,应该是这样的:

package barsoftware.suedtirolpointer;

import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.Manifest;
import android.content.pm.PackageManager;

public class Berechtigungen extends AppCompatActivity {

final int REQ_CODE_EXTERNAL_STORAGE_PERMISSION = 45;

public void GPS() {

if (ActivityCompat.checkSelfPermission(Berechtigungen.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
//

} else {

ActivityCompat.requestPermissions(Berechtigungen.this,
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
REQ_CODE_EXTERNAL_STORAGE_PERMISSION);
}
}

private void createFolder() {

File ordner = new File(Environment.getExternalStorageDirectory(), "TestOrdner");
ordner.mkdirs();
Toast.makeText(getApplicationContext(), "Ordner erstellt", Toast.LENGTH_SHORT).show();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == REQ_CODE_EXTERNAL_STORAGE_PERMISSION
&& grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
createFolder();
}
}
}

关于java - Android Java 类中的非法类型 'void',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44377771/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com