Sorun: A almakta zorlanıyorum. FileChooser
a doldurmak için sınıf TextView
sırasında bir TableRow
yaratılış. Bir alamıyorum Invocation Exception
android'de "looper" oluşturuldu.bir değişkenin neden olduğu java" tagTrace=0
olmak okundu olarak "!=0". Bu yüzden, bu sorunu nasıl çözebileceğimden emin değilim.
Yapmaya çalıştığım şey: Varolan bir süreç üzerine inşa etmeye çalışıyorum. Bir kullanıcı başlık satırında bir " + " düğmesine tıkladığında TableLayout
, iki görünüme sahip bir satır oluşturur: bir" Sil" ( -) Button
sırada.çocuk (0) ve a TextView
sırada.çocuk (1). Başarılı bir şekilde yapar. Bir ... var Singleton
çeşitli türleri yöneten sınıf TableRow
tüm uygulama için kreasyonlar Actiities
.
Belirli bir konuda Activity
bir Dosya var TableLayout
. Yukarıda tarif ettiğim "+" düğmesine tıklandığında kullanıcının bir tane başlatmasını istiyorum. FileChooser
bir dosya yolunu yakalamak ve bu yolu doldurmak için TextView
oluşturduğu satırın alt öğesi. Ancak, yukarıdaki sorunla karşılaşıyorum.
Lüper.çağırma istisnasına neden olan java Hatası (sanırım)
FileChooser
public class FileChooser extends AppCompatActivity {
private String fileName;
private String filePath;
private final ActivityResultLauncher<Intent> resultLauncher;
public FileChooser(){
//if(intent==null) Toast.makeText(null, "Intent is Null", Toast.LENGTH_SHORT).show();
this.resultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null){
Uri uri = result.getData().getData();
filePath = uri.getPath();
}
});
}
public String getFileName() {
return fileName;
}
public String getFilePath() {
return filePath;
}
public ActivityResultLauncher<Intent> getResultLauncher() {
return resultLauncher;
}
}
Tablerow'u yaratan Singleton içindeki yöntem"!kalın"
public static TableRow setupFilesTableRow(Context context, TableLayout table, String fileID, String fileName, boolean bold) {
TableRow row = new TableRow(context);
if(bold) {
row.addView(setupFilesAddRowButton(context, table));
row.addView(addRowTextViewToTable(context, fileName, true));
}
if (!bold) {
row.addView(setupDeleteRowButton(context, table));
// Intent and FileChooser to capture a filePath
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
FileChooser fileChooser = new FileChooser();
fileChooser.getResultLauncher().launch(intent);
// Adding a TextView child to the new TableRow with the captured filePath from the FileChooser
row.addView(addRowTextViewToTable(context, fileChooser.getFilePath(), false));
//row.setClickable(true);
}
return row;
}