Приложение работает на эмуляторе, но вылетает на физических устройствахJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Приложение работает на эмуляторе, но вылетает на физических устройствах

Сообщение Anonymous »

У меня есть метод, который работает на эмуляторе в Android Studio, но дает сбой на физическом устройстве. Я пробовал это на двух разных устройствах.
Это не графическое изображение, поэтому оно не связано с разрешением.
Это код

Код: Выделить всё

public void selectLexiconForDeletion(){
// only called from Select options, not when loading
databaseAccess = DatabaseAccess.getInstance(this, LexData.getDatabasePath(), LexData.getDatabase());
ArrayList lexiconList = databaseAccess.get_lexicons();

if (!lexiconList.isEmpty()) {
ArrayList options= new ArrayList();
for (int c = 0; c < lexiconList.size(); c++) {
options.add(lexiconList.get(c).LexiconName);
}
final String[] opts;
opts = options.toArray(new String[]{});
Log.d("opts", String.valueOf(opts.length));

final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select");
builder.setItems(opts, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// opts[item] is the name of the lexicon

dialog.dismiss();
deleteLexiconAlert(opts[item]);

}
});
builder.show();
}
}

Это сообщение об ошибке, указывающее на строку builder.show(); В журнале видно, что записи успешно считаны из базы данных.

Код: Выделить всё

2025-01-08 08:03:07.401 13922-13922 AndroidRuntime          com.tylerhosting.hoot
E  FATAL EXCEPTION: main

Process: com.tylerhosting.hoot, PID: 13922

android.content.res.Resources$NotFoundException: Resource ID #0x0

at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)

at android.content.res.Resources.loadXmlResourceParser(Resources.java:2148)

at android.content.res.Resources.getLayout(Resources.java:1157)

at android.view.LayoutInflater.inflate(LayoutInflater.java:421)

at android.view.LayoutInflater.inflate(LayoutInflater.java:374)

at android.support.v7.app.AlertController$AlertParams.createListView(AlertController.java:989)

at android.support.v7.app.AlertController$AlertParams.apply(AlertController.java:965)

at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:982)

at android.support.v7.app.AlertDialog$Builder.show(AlertDialog.java:1006)

at com.tylerhosting.hoot.hoot.ToolsActivity.selectLexiconForDeletion(ToolsActivity.java:670)

at com.tylerhosting.hoot.hoot.ToolsActivity$11.onClick(ToolsActivity.java:426)

at android.view.View.performClick(View.java:6892)

at android.widget.TextView.performClick(TextView.java:12693)

at android.view.View$PerformClick.run(View.java:26104)

at android.os.Handler.handleCallback(Handler.java:789)

at android.os.Handler.dispatchMessage(Handler.java:98)

at android.os.Looper.loop(Looper.java:164)

at android.app.ActivityThread.main(ActivityThread.java:6944)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Как ни странно, та же процедура без проблем используется в другом файле. Он — код для этого.

Код: Выделить всё

        public void selectLexicon(){
// only called from Select options, not when loading
databaseAccess = DatabaseAccess.getInstance(getActivity().getApplicationContext() , LexData.getDatabasePath(), LexData.getDatabase());
ArrayList lexiconList = databaseAccess.get_lexicons();

if (lexiconList.size() > 0) {
ArrayList options=new ArrayList();
for (int c = 0; c < lexiconList.size(); c++) {
options.add(lexiconList.get(c).LexiconName);
}
final String[] opts;
opts = options.toArray(new String[]{});

final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select");
builder.setItems(opts, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// opts[item] is the name of the lexicon

dialog.dismiss();
setLexicon(opts[item]);

// I THOUGHT setLexicon did this
//                        LexData.setLexicon(getActivity().getApplicationContext(), opts[item]);
//                        Utils.setLexiconPreference(getActivity().getApplicationContext());
}
});
builder.show();
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
Log.i("SetSelectLexiconPrefs", shared.getString("lexicon", "x"));

Оба используют
import android.support.v7.app.AlertDialog;

Подробнее здесь: https://stackoverflow.com/questions/793 ... al-devices
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»