【发布时间】:2021-09-16 22:37:57
【问题描述】:
我的目标:修复此错误并能够无错误地运行我的应用程序。
错误信息: 注意: D:\Learning\app\src\main\java\com\example\learning\MainActivity.java 使用或覆盖已弃用的 API。注意:重新编译 -Xlint:deprecation 了解详情。
我在“构建输出”中收到以下错误。我试图解决这个问题,但每次尝试都失败了。我在 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());
}
}
}
提前致谢!
【问题讨论】:
标签: java android android-studio