gpt4 book ai didi

java - 语法错误 : Constructor call must be the first statement in a constructor

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:27 25 4
gpt4 key购买 nike

我正在为应用程序设置创建一个导航应用程序。
为此,我正在创建以下代码,但是,正如我在上面的标题中提到的,我遇到了语法错误。
请指导我解决这个问题。

这是我的MainActivity.Java

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

public MainActivity() {

}

private boolean MyStartActivity(Intent intent) {
try {
startActivity(intent);
} catch (ActivityNotFoundException activitynotfoundexception) {
return false;
}

return true;
}

protected boolean isAppInstalled(String s) {
PackageManager packagemanager = getPackageManager();

try {
packagemanager.getPackageInfo(s, 128);
} catch (android.content.pm.PackageManager.NameNotFoundException namenotfoundexception) {
return false;
}

return true;
}

protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(0x7f030000);

if (getIntent().getIntExtra("reload", 0) == 1) {
if (isAppInstalled("com.sample.test")) {
Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:com.sample.test"));
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Game Not Instaled", 0).show();
}
}

((Button)findViewById(0x7f080000)).setOnClickListener(new android.view.View.OnClickListener() {
final MainActivity this$0;

public void onClick(View view) {
if (isAppInstalled("com.sample.test")) {
Intent intent1 = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
intent1.addCategory("android.intent.category.DEFAULT");
intent1.setData(Uri.parse("package:com.sample.test"));
startActivity(intent1);

return;
} else {
Toast.makeText(getApplicationContext(), "Game Not Instaled", 0).show();

return;
}
}

{
this$0 = MainActivity.this;
super(); //Constructor call must be the first statement in a constructor
}
});
}

}

最佳答案

你创建了一个匿名内部类:

new android.view.View.OnClickListener() {
// code exists here

super();
}

并在该类的底部调用 super();,这是 super 构造函数调用。这个电话必须是第一个,但在你的情况下是完全没有必要的。只需将其删除即可。

关于java - 语法错误 : Constructor call must be the first statement in a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22986391/

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