gpt4 book ai didi

java - 注意 : MainActivity uses or overrides a deprecated API. 注意:使用 -Xlint:deprecation 重新编译以获取详细信息

转载 作者:行者123 更新时间:2023-12-05 05:56:17 25 4
gpt4 key购买 nike

My Goal: To fix this error and be able to run my app without an error.

Error Message: Note:D:\Learning\app\src\main\java\com\example\learning\MainActivity.javauses or overrides a deprecated API. Note: Recompile with-Xlint:deprecation for details.

我在“构建输出”中收到以下错误。我试图解决这个问题,但每次尝试都不成功。我在 Stackoverflow 上找到了一些与此错误相关的问题,但它不符合我的需求,所以我决定问我自己的问题,希望有人能帮助我解决这个错误。

public class MainActivity extends AppCompatActivity {

static final int REQUEST_IMAGE_CAPTURE = 1;
String currentPhotoPath;
Button sendBtn;
EditText nameText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

nameText = (EditText)findViewById(R.id.editText);
sendBtn = (Button)findViewById(R.id.button2);

}

public void dispatchTakePictureIntent(){
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

try {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}catch (ActivityNotFoundException e){
//dispaly error
}
}

private File createImageFile() throws IOException{
//Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = " JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);

// Save a file: path for use with ACTION_VIEW intents
currentPhotoPath = image.getAbsolutePath();
return image;
}

public void onClick(View view){

dispatchTakePictureIntent();

}


public void onClick2(View view) {

SqlAdapter sqlAdapter = new SqlAdapter();

try {
Connection con = sqlAdapter.connectionclass();
String query = "INSERT INTO dbo.Test(text) VALUES ('" + nameText.getText().toString() + "') ";
Statement stmt = con.createStatement();
stmt.executeUpdate(query);
}
catch (SQLException sqlException){
Log.e("ERROR", sqlException.getMessage());
}

}
}

提前致谢!

最佳答案

startActivityForResult(…) 在 AndroidX Activity (AppCompatActivity) 中被弃用。

他们在 ComponentActivity(AppCompatActivity 的基类)中创建了一个名为 registerForActivityResult(…) 的替代品,这应该会更好。

参见 my answer in another questiondocumentation for registerForActivityResult(…) .

关于java - 注意 : MainActivity uses or overrides a deprecated API. 注意:使用 -Xlint:deprecation 重新编译以获取详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69208123/

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