- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 editText1、editText2 和 EditText3 .用户需要在此区域写入个人信息。当他们按下保存按钮时, editText1、editText2 和 EditText3 必须保存。他们应该在他们想要的时候找到他们写的东西。但是当我尝试保存 其中 3 个(editText1、editText2 和 EditText3) ,这不会发生。 我可以只保存editText1 .或者我可以在 editText1 中保存 3 个空格区域。例如,我在editText1“你好”,在editText2“听”,在editText3“伙计们”中写道,我正在保存这个,当我在保存区域打开时,我可以看到3次“听”。其他不保存。 你能帮助我吗?我应该改变什么?
主要 Activity :
public class MainActivity extends AppCompatActivity {
static ArrayList<Bitmap> newImage;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.add_new, menu);
return super.onCreateOptionsMenu(menu);
}
@Override //Menüyü seçersek ne olacak onu belirler.
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.add_new) {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "new"); //Bu satırda amaç eğer yeni bir resimmi yoksa eski resimmi görentülenmek isteniyor onu anlamak
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listView);
//Databaseden çektiğimiz dataları kaydedeceğimiz bir arraylist oluşturalım ve listview ile bağlayalım
final ArrayList<String> newName = new ArrayList<String>();
final ArrayList<String> newName2 = new ArrayList<String>();
final ArrayList<String> newName3 = new ArrayList<String>();
newImage = new ArrayList<Bitmap>();
ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,newName);
listView.setAdapter(arrayAdapter);
//uygulama ilk açıldığında database'de kayıtlı bir şey varmı bakmasını istiyoruz aşağıdaki aşamalarda
try {
Main2Activity.database = this.openOrCreateDatabase("Yeni", MODE_PRIVATE, null);
Main2Activity.database.execSQL("CREATE TABLE IF NOT EXISTS yeni (name VARCHAR, name2 VARCHAR, name3 VARCHAR, image BLOB)");
Cursor cursor = Main2Activity.database.rawQuery("SELECT * FROM yeni", null); //Data çekmek için cursoru kullanıyoruz
int nameIx = cursor.getColumnIndex("name");
int name2Ix = cursor.getColumnIndex("name2");
int name3Ix = cursor.getColumnIndex("name3");
int imageIx = cursor.getColumnIndex("image");
cursor.moveToFirst();
while (cursor != null) {
newName.add(cursor.getString(nameIx)); //Kullanıcının girdği ismi newName'in içine ekle
newName2.add(cursor.getString(name2Ix));
newName3.add(cursor.getString(name3Ix));
byte[] byteArray = cursor.getBlob((imageIx));
Bitmap image = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);
newImage.add(image); //newImage'in içine ekle diyoruz
cursor.moveToNext();
arrayAdapter.notifyDataSetChanged();//Eğer bir datayı değiştirdiysek hemen güncelleyen bir konut
}
} catch (Exception e) {
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent (getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "old");
intent.putExtra("name", newName.get(position));
intent.putExtra("name2", newName2.get(position));
intent.putExtra("name3", newName3.get(position));
intent.putExtra("position", position);
startActivity(intent);
}
});
}
}
public class Main2Activity extends AppCompatActivity {
ImageView imageView; //imageView'i heryerde tanımladık
EditText editText;
EditText editText2;
EditText editText3;
static SQLiteDatabase database; //Buraya yazdığımız database'e MainActivity'den de ulaşabileceğiz çünkü statik yazdık
Bitmap selectedImage; //seçilen resmi kaydetmek için burada bunu tanımladık
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView) findViewById(R.id.imageView); //layouttaki imageView'i tanımladık
editText = (EditText) findViewById(R.id.editText);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
Button button = (Button) findViewById(R.id.button); //Buton tanımladık
Intent intent = getIntent();
String info = intent.getStringExtra("info"); //MainActivity'deki 28. satırla bağlantılı
if (info.equalsIgnoreCase("new")) {
Bitmap background = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.dede); //Kullanıcı resim seçerkenki aşama
imageView.setImageBitmap(background);
button.setVisibility(View.VISIBLE); //Eğer yeni eklenecekse görünür yap
editText.setText(""); //Bu satır eğer daha önceden bir şey yazdıysak onun orada kalmamasını bize boş yazma yeri açmasını sağlıyor
editText2.setText("");
editText3.setText("");
} else {
String name = intent.getStringExtra("name");
editText.setText(name);
String name2 = intent.getStringExtra("name2");
editText2.setText(name2);
String name3 = intent.getStringExtra("name3");
editText3.setText(name3);
int position = intent.getIntExtra("position", 0);
imageView.setImageBitmap(MainActivity.newImage.get(position));
button.setVisibility(View.INVISIBLE); //Eskiyse gösterme
}
}
//Resim koyma yerine tıklandığında olacaklar
public void select (View view) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
} else {
Intent intent = new Intent (Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); //Kullanıcının medyasına eriş diyoruz
startActivityForResult(intent,1);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == 2) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Intent intent = new Intent (Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); //Kullanıcının medyasına eriş diyoruz
startActivityForResult(intent,1);
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
//Yukarıdaki medyaya erişime izin verildiyse resim seçme yeri
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK && data!= null) {
Uri image = data.getData();
//try ve catch ın içine aldık bu olayı çünkü bi sorun çıkarsa burda uygulama hata vermesin.
try {
selectedImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), image);
imageView.setImageBitmap(selectedImage); //imageView'e burda ulaşmak için koyduk
} catch (IOException e) {
e.printStackTrace();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
// Kaydetme butonuna tıklandığında olacaklar
public void save (View view) {
String newName = editText.getText().toString(); //Kullanıcının kardettiği isme bu şekilde ulaştık
String newName2 = editText2.getText().toString();
String newName3 = editText3.getText().toString();
//image'ler bytearray şeklinde kaydedilir!!!!!!!!!!
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //selectedImage'i compress etmeliyiz kaydetme aşamalarından biri
selectedImage.compress(Bitmap.CompressFormat.PNG,50,outputStream); //bu şekilde ziplemiş olduk resmi
byte[] byteArray = outputStream.toByteArray(); //Bu outpuSteam'i al array'e çevir dedik! ve resmimiz kaydedilebilir oldu
try { //Tüm bu alttaki aşamalarda kullanıcının girdiği isim ve resmi database'imize işlemiş olduk!
database = this.openOrCreateDatabase("Yeni", MODE_PRIVATE, null);
database.execSQL("CREATE TABLE IF NOT EXISTS yeni (name VARCHAR, image BLOB)");
String sqlString = "INSERT INTO yeni (name, image) VALUES (?, ?, ?, ?)";
SQLiteStatement statement =database.compileStatement(sqlString);
statement.bindString(1,newName);
statement.bindString(3,newName2);
statement.bindString(4,newName3);
statement.bindBlob(2,byteArray);
statement.execute();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class); //kaydet'e bastığında anasayfaya yönlendirilsin
startActivity(intent);
}
}
最佳答案
问题 1 是您尝试定义同一个表,但有 4 列(在 onCreate
的 MainActivity
方法中),然后使用 2 列(在 save
的 Main2Activity
方法中),第二个不会将表创建为它已经被创建了,所以看起来 4 列版本将存在(如果它不存在并且表被创建,那么每当您返回 MainActivity
作为两列(name2
和name3
) 将不存在并导致在尝试 int name2Ix = cursor.getColumnIndex("name2");
时找不到列。
一个 第二期是您尝试插入 2 个值,但将 4 个值作为参数给出,即 INSERT INTO yeni (name,image) ....
2 个值 VALUES(?, ?, ? ,?)
4个论据。
一个 第三期是您没有检测到插入的成功或失败,而只是假设它会起作用(当它不起作用时)。在 SQLiteDatabase 方法周围使用 try/catch 也不是一个好主意,因为它们通常会处理许多情况,并且只会在出现严重错误时崩溃(并且您想要崩溃)。
一个 第四期是您可以单击保存按钮(假设您在布局中使用了android:onClick="save"
),selectedImage
很可能是空的。
一个 第五期是用 Main2Activity
完成后你尝试开始MainActivity
,这将开始另一个 Activity ,而不是您通过完成 Main2Activity
返回它.目前,这对您有利,因为 ListView 列出了新插入的行。但是,您最终会获得大量 Activity ,并且点击后退按钮将逐步返回 Activity 堆栈,并且会非常困惑。
修复第5个问题,即完成Main2Activty
介绍了 第6期那就是 List 没有刷新,它保持在插入新行之前的状态。
修复第 6 个问题需要更改许多代码,但最终您通过覆盖 onResume
来刷新列表通过重建 List 的源(清除 ArrayList 然后将所有元素添加到其中)的方法。
第 4 期的临时修复。
忽略第一个问题,这不会导致问题,因为看起来首先创建了具有 4 列的表(当然是在测试中)。
并且最初也忽略了第 2 和第 3 期。但是使用:-
if (info.equalsIgnoreCase("new")) { // UNCHANGED
Bitmap background = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
android.R.drawable.ic_dialog_alert //<<<< Use a stock Android image for testing
); //Kullanıcı resim seçerkenki aşama
selectedImage = background; //<<<< ADDED to overcome null pointer exception
imageView.setImageBitmap(background); //<<<< UNCHANGED
//........ rest of the code
Main2Activity
的
onCreate
方法和输入在 3 个 EditText 中的测试、测试和测试,然后单击按钮会导致返回到 MainActivity 但没有显示任何内容。但是,日志显示预期的
E/SQLiteLog: (1) 4 values for 2 columns
:-
06-03 22:13:09.895 2647-2647/yeni.yeni E/SQLiteLog: (1) 4 values for 2 columns
06-03 22:13:09.895 2647-2647/yeni.yeni W/System.err: android.database.sqlite.SQLiteException: 4 values for 2 columns (code 1): , while compiling: INSERT INTO yeni (name, image) VALUES (?, ?, ?, ?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:994)
at yeni.yeni.Main2Activity.save(Main2Activity.java:145)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
public void save (View view) {
String newName = editText.getText().toString(); //Kullanıcının kardettiği isme bu şekilde ulaştık
String newName2 = editText2.getText().toString();
String newName3 = editText3.getText().toString();
//image'ler bytearray şeklinde kaydedilir!!!!!!!!!!
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //selectedImage'i compress etmeliyiz kaydetme aşamalarından biri
selectedImage.compress(Bitmap.CompressFormat.PNG,50,outputStream); //bu şekilde ziplemiş olduk resmi
byte[] byteArray = outputStream.toByteArray(); //Bu outpuSteam'i al array'e çevir dedik! ve resmimiz kaydedilebilir oldu
ContentValues cv = new ContentValues();
cv.put("name",newName);
cv.put("name2",newName2);
cv.put("name3",newName3);
cv.put("image",byteArray);
long new_row_id = database.insert("yeni",null,cv);
//<<<< ADDED TO ISSUE TOAST WITH THE RESULT
if (new_row_id > 0) {
Toast.makeText(this,"Row Insereted.",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,"Row NOT Inserted",Toast.LENGTH_SHORT).show();
}
/*
try { //Tüm bu alttaki aşamalarda kullanıcının girdiği isim ve resmi database'imize işlemiş olduk!
Log.d("SAVE","Attempting OPEN Or CREATE DATABASE");
database = this.openOrCreateDatabase("Yeni", MODE_PRIVATE, null);
Log.d("SAVE","Attempting CREATE OF TABLE yeni");
database.execSQL("CREATE TABLE IF NOT EXISTS yeni (name VARCHAR, image BLOB)");
String sqlString = "INSERT INTO yeni (name, image) VALUES (?, ?, ?, ?)";
SQLiteStatement statement =database.compileStatement(sqlString);
statement.bindString(1,newName);
statement.bindString(3,newName2);
statement.bindString(4,newName3);
statement.bindBlob(2,byteArray);
Log.d("SAVE","Attempting EXECUTION of the SQL INSERT using :- " + statement.toString());
statement.execute();
} catch (Exception e) {
e.printStackTrace();
}
*/
Intent intent = new Intent(getApplicationContext(), MainActivity.class); //kaydet'e bastığında anasayfaya yönlendirilsin
startActivity(intent);
//this.finish(); //<<<< Should not start a parent activity you should return to it by finishing the child activity
}
onResume
刷新列表
中的方法MainActivity
public class MainActivity extends AppCompatActivity {
static ArrayList<Bitmap> newImage;
ArrayList<String> nameList;
ArrayList<String> name2List;
ArrayList<String> name3List;
ArrayAdapter<String> arrayadpater;
ListView listView;
Button addbutton; //<<<< Instead of menu for my convenience
//<<<<<<<<<< Code Commented out for convenience of using button >>>>>>>>>
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.add_new, menu);
return super.onCreateOptionsMenu(menu);
}
@Override //Menüyü seçersek ne olacak onu belirler.
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.add_new) {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "new"); //Bu satırda amaç eğer yeni bir resimmi yoksa eski resimmi görentülenmek isteniyor onu anlamak
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listview); //<<<< CHANGED as declared as class variable
//<<<<<<<<<< Code below for the conveince of using a button instead of Menu >>>>>>>>>>
addbutton = (Button) findViewById(R.id.addnew);
addbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "new"); //Bu satırda amaç eğer yeni bir resimmi yoksa eski resimmi görentülenmek isteniyor onu anlamak
startActivity(intent);
}
});
//<<<<<<<<<< End of code for Button handling >>>>>>>>>>
setupListView();
//<<<<<<<<<< NOTE commented out Code >>>>>>>>>>
/*
//Databaseden çektiğimiz dataları kaydedeceğimiz bir arraylist oluşturalım ve listview ile bağlayalım
final ArrayList<String> newName = new ArrayList<String>();
final ArrayList<String> newName2 = new ArrayList<String>();
final ArrayList<String> newName3 = new ArrayList<String>();
newImage = new ArrayList<Bitmap>();
ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,newName);
listView.setAdapter(arrayAdapter);
//uygulama ilk açıldığında database'de kayıtlı bir şey varmı bakmasını istiyoruz aşağıdaki aşamalarda
try {
Main2Activity.database = this.openOrCreateDatabase("Yeni", MODE_PRIVATE, null);
Main2Activity.database.execSQL("CREATE TABLE IF NOT EXISTS yeni (name VARCHAR, name2 VARCHAR, name3 VARCHAR, image BLOB)");
Cursor cursor = Main2Activity.database.rawQuery("SELECT * FROM yeni", null); //Data çekmek için cursoru kullanıyoruz
int nameIx = cursor.getColumnIndex("name");
int name2Ix = cursor.getColumnIndex("name2");
int name3Ix = cursor.getColumnIndex("name3");
int imageIx = cursor.getColumnIndex("image");
cursor.moveToFirst();
while (cursor != null) {
newName.add(cursor.getString(nameIx)); //Kullanıcının girdği ismi newName'in içine ekle
newName2.add(cursor.getString(name2Ix));
newName3.add(cursor.getString(name3Ix));
byte[] byteArray = cursor.getBlob((imageIx));
Bitmap image = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);
newImage.add(image); //newImage'in içine ekle diyoruz
cursor.moveToNext();
arrayAdapter.notifyDataSetChanged();//Eğer bir datayı değiştirdiysek hemen güncelleyen bir konut
}
} catch (Exception e) {
}
*/
}
//<<<< ADDED to handle return from child >>>>
@Override
public void onResume() {
super.onResume();
setupListView();
}
//<<<< ADDED to utilise a single refreshable ListView
private void setupListView() {
getListsFromDatabase();
if (arrayadpater == null) {
arrayadpater = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,nameList);
listView.setAdapter(arrayadpater);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent (getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "old");
intent.putExtra("name", nameList.get(position));
intent.putExtra("name2", name2List.get(position));
intent.putExtra("name3", name3List.get(position));
intent.putExtra("position", position);
startActivity(intent);
}
});
} else {
arrayadpater.notifyDataSetChanged();
}
}
//<<<< Added to build/rebuild the Arraylist's used by the ListView
private void getListsFromDatabase() {
// Get the database (and set the databse for Main2Acticity)
SQLiteDatabase db = openOrCreateDatabase(
"Yeni",
MODE_PRIVATE,
null
);
db.execSQL("CREATE TABLE IF NOT EXISTS yeni (name VARCHAR, name2 VARCHAR, name3 VARCHAR, image BLOB)");
Main2Activity.database = db;
// Initialise or clear the array lists
if (nameList == null) {
nameList = new ArrayList<>();
} else {
nameList.clear();
}
if (name2List == null) {
name2List = new ArrayList<>();
} else {
name2List.clear();
}
if (name3List == null) {
name3List = new ArrayList<>();
} else {
name3List.clear();
}
if (newImage == null) {
newImage = new ArrayList<>();
} else {
newImage.clear();
}
// get the
Cursor cursor = db.query("yeni",
null,
null,
null,
null,
null,
null
);
while (cursor.moveToNext()) {
nameList.add(cursor.getString(cursor.getColumnIndex("name")));
name2List.add(cursor.getString(cursor.getColumnIndex("name2")));
name3List.add(cursor.getString(cursor.getColumnIndex("name3")));
byte[] b = cursor.getBlob(cursor.getColumnIndex("image"));
Bitmap bmp = BitmapFactory.decodeByteArray(b,0,b.length);
newImage.add(bmp);
}
cursor.close();
}
}
Main2Activity
删除 2 行:-
Intent intent = new Intent(getApplicationContext(), MainActivity.class); //kaydet'e bastığında anasayfaya yönlendirilsin
startActivity(intent);
this.finish(); //<<<< ADD this to finish Main2Activity and return to MainActivity
关于java - 尝试使用 SqliteDatabase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50671821/
说真的,你怎么能在不发疯的情况下处理所有这些异常呢?我是不是读了太多关于异常处理的文章或什么?我尝试重构了几次,但每次似乎都以更糟糕的结果告终。也许我应该承认确实会发生异常(exception)情况,
背景 两者 try/rescue和 try/catch是 Elixir 中的错误处理技术。根据 corresponding chapter在介绍指南中。 Errors can be rescued u
每当我尝试在 Raspberry PI 上运行此 python 脚本时,我都会遇到问题: import socket import sys # Create a TCP/IP socket sock
我想知道一些关于 PHP 的 try , catch声明。 让我们考虑以下示例。 abstract class ExceptionA extends Exception {} class Except
我的 laravel v5.4 项目中有两个模型,user 和 admin。 在 config/auth.php 中,我向守卫和提供者添加了管理员,如下所示: 'guards' => [ 'w
try: r = requests.get(url, params={'s': thing}) except requests.ConnectionError, e: print e
我有以下代码。 但是,它并不能捕获所有错误,而我仍然会收到“throw er;//未处理的'错误'事件”。 为什么是这样? app.post('/api/properties/zip/:zip/bed
问题与细节 我正在使用自定义错误处理,遇到的错误之一是“路径中的非法字符”。我有一个自定义函数,旨在通过路径字符串查找此类非法字符,并在找到它们时引发自定义错误。但是我发现,取决于非法字符,Test-
This question already has answers here: How do I catch a numpy warning like it's an exception (not j
我正在使用其他人的代码,但我不熟悉try/catch,因此我举了一个类似的小例子。在第11行上,如果我写了error(''),似乎没有发现错误并增加了索引j。但是,编写error(' ')或error
我在我的一个程序中遇到了这个问题,在这种情况下,尝试/异常(exception)的错误使程序变得更好,以防用户意外输入了他们不应该输入的内容。它仍然给我错误,我为为什么感到困惑。如果对我的问题确实很重
我在尝试TRY ... CATCH块时遇到问题。有人可以解释为什么以下代码无法执行我的sp吗? DECLARE @Result int SET @Result = 0 BEGIN TRY SE
我有一个相当大的 powershell 脚本,其中包含许多(20 多个)执行各种操作的函数。 现在所有代码实际上都没有任何错误处理或重试功能。如果某个特定的任务/功能失败,它就会失败并继续。 我想改进
为什么我尝试时需要导入 inputmismatchException catch(InputMismatchException e){ System.out.println("
我对此感到困惑 - 我为辅助方法编写了一个 try/catch 。它的目的是捕获任何无效输入(任何不是“男性”或“女性”的内容(没有特定情况)。如果输入无效,它将通知用户,然后让他们重试。如果有效,则
我有时会发现自己处于如下场景。尽可能简单地陈述问题 “有时我会创建一段代码,Java 让我将其包含在 try/catch 语句中。我没有使用 catch,所以我将其留空。为什么这是错误的?” boo
我有点困惑为什么当我不使用 Try block 时会出现 Try block 错误。 我在代码块底部附近收到错误通知。如果我不使用 try/catch,有人可以向我解释为什么会发生这种情况吗? 它是否
我已经盯着我的电脑两个小时了,我不知道我做错了什么。谁能帮助我看到光明? package blackjack; import java.util.Random; import java.util.Sc
我想将方法保存在 Enum 中,但 Class.getDeclaredMethod 抛出 NoSuchMethodException,那么我该如何处理呢?我的代码: public enum Car
这个问题已经有答案了: Executing multi-line statements in the one-line command-line (18 个回答) 已关闭 3 年前。 如何使用try.
我是一名优秀的程序员,十分优秀!