以下编码有问题。
new AlertDialog.Builder(this)
这个有错误,请帮我看看。
import java.io.File;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
public static boolean isPhoneRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
} catch (Throwable e1) {
// ignore
}
return false;
}
}
最佳答案
这里:
public static boolean isPhoneRooted() {
...
new AlertDialog.Builder(this)
....
}
是明确不允许的。
因为该方法是 class方法而不是 instance方法,this 实际上并不存在(因为 this
是事物的实际实例)。
这是真正的基本内容,您可能应该阅读一下。 Here's比较两者的链接。
关于java - 无法在静态上下文中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22624976/