gpt4 book ai didi

java - 找不到符号“上下文”,android.content.Context

转载 作者:行者123 更新时间:2023-12-01 19:53:24 26 4
gpt4 key购买 nike

我有以下代码:

package com.androidtest.notification;

import android.app.Activity;
import android.os.Bundle;
import android.widget;
import android.widget.Toast;
import android.content.Context;

public class activityNotification extends Activity
{

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}


我正在尝试在命令行“ $ ant build”上使用ant对其进行编译,但我不断收到以下错误:

error: cannot find symbol
[javac] Context context = getApplicationContext();
[javac] ^


有什么建议吗?谢谢!

最佳答案

简短答案:添加此

import android.content.Context;

关于java - 找不到符号“上下文”,android.content.Context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59066623/

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