PriceScannerApp: warum wird nach dem Scannen Display gleich schwarz?

nata

Bekanntes Mitglied
Hallo Leute,

Ich habe 2 Activity Klassen und für Datenbank Product , MySQLiteHelper und ProductDataSource.
Wenn ich auf Scan Product drücke wird Scannen gestartet, aber gleich wird Display schwarz. Woran liegt mein Fehler?


Java:
public class MainActivity extends Activity {
    public static final String EXTRA_BARCODE = "extraBarcode";
    public static final String EXTRA_FORMAT = "extraFormat";
    public final static String EXTRA_MESSAGE = "com.example.pricescannerapp.MESSAGE";
 
    public boolean mainIsOpen = true;
 
    private IntentIntegrator mIntentIntegrator;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        this.mIntentIntegrator = new IntentIntegrator(this);
 
    }
 
    public void scanProduct(View view) {
 
        this.mIntentIntegrator.initiateScan();
 
    }
 
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(
                requestCode, resultCode, intent);
 
        if (scanResult != null) {
            Intent intent1 = new Intent(this, EnterProductDetailActivity.class);
            intent1.putExtra(EXTRA_BARCODE, scanResult.getContents());
            intent1.putExtra(EXTRA_FORMAT, scanResult.getFormatName());
            startActivity(intent1);
 
        }
 
        try {
 
        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
        }
    }
 
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
 
        if (keyCode == KeyEvent.KEYCODE_BACK && mainIsOpen == false) {
            mainIsOpen = true;
            setContentView(R.layout.activity_main);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
 
}

Java:
public class EnterProductDetailActivity extends Activity {
 
    SQLiteDatabase database;
    MySQLiteHelper dbHelper;
 
    List<Product> productsList = new ArrayList<Product>();
 
    private ProductDataSource datasource;
   
    String barcode;
    String format;
    EditText editbarcode;
    EditText editformat;
 
    boolean mainIsOpen;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enter_product_detail);
 
        // Instantiate own SQlite helper class
        dbHelper = new MySQLiteHelper(this);
        database = dbHelper.getWritableDatabase();
       
       
        datasource = new ProductDataSource(this);
 
        // Get the message from the intent
        Intent intent = getIntent();
        barcode = intent.getStringExtra(MainActivity.EXTRA_BARCODE);
        format = intent.getStringExtra(MainActivity.EXTRA_FORMAT);
        editbarcode = (EditText) findViewById(R.id.etBarcode);
        editformat = (EditText) findViewById(R.id.etType);
 
        editbarcode.setText(barcode);
        editformat.setText(format);
 
    }
 
 
    public void showProducts(View view) {
        setContentView(R.layout.activity_formular_filled);
        mainIsOpen = false;
       
        productsList.clear();
        try {
            datasource.open();
            productsList = datasource.getAllProducts();
            datasource.close();
        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
        }
 
        ArrayAdapter<Product> adapterProduct = new ArrayAdapter<Product>(
                EnterProductDetailActivity.this, android.R.layout.simple_list_item_1,
                productsList);
 
        ListView lVerlauf = (ListView) findViewById(R.id.listView1);
        lVerlauf.setAdapter(adapterProduct);
 
    }
   
 
   
    public void saveProduct(View view) {
 
        dbHelper = new MySQLiteHelper(this);
        database = dbHelper.getWritableDatabase();
       
        try {
            datasource.open();
            datasource.createProduct(barcode, format);
            datasource.close();
        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
        }
       
    }
 
   
}

Java:
public class MySQLiteHelper extends SQLiteOpenHelper {
 
    private static final String DATABASE_NAME = "products.db";
    private static final int DATABASE_VERSION = 11;
 
    private static final String TEXT_TYPE = " TEXT";
    private static final String COMMA_SEP = ", ";
   
   
    public static final String TABLE_NAME = "PRODUCTS ";
    public static final String PRODUCT_ID = "ID ";
    public static final String COLOMN_BARCODE = "BARCODE ";
    public static final String COLOMN_TYPE = "TYPE ";
   
   
   
    private static final String CREATE_TABLE_PRODUCTS = "CREATE TABLE "
            + TABLE_NAME + " (" + PRODUCT_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT" + COMMA_SEP + COLOMN_BARCODE
            + TEXT_TYPE + COMMA_SEP + COLOMN_TYPE
            + TEXT_TYPE +
            " )";
 
 
    private static final String SQL_DELETE_PRODUCTS = "DROP TABLE IS EXISTS" + TABLE_NAME;
 
    public MySQLiteHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
 
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_PRODUCTS);
 
    }
 
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_PRODUCTS);
        onCreate(db);
 
    }
   
    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
 
}
Java:
public class ProductDataSource {
    SQLiteDatabase database;
    MySQLiteHelper dbHelper;
    private String[] allColumns = { MySQLiteHelper.PRODUCT_ID,
            MySQLiteHelper.COLOMN_BARCODE, MySQLiteHelper.COLOMN_TYPE };
 
    public ProductDataSource(Context context) {
        // TODO Auto-generated constructor stub
        dbHelper = new MySQLiteHelper(context);
    }
 
    public void open() throws Exception {
        database = dbHelper.getWritableDatabase();
    }
 
    public void close() {
        dbHelper.close();
    }
 
    public Product createProduct(String barcode, String type) {
        ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLOMN_BARCODE, barcode);
        values.put(MySQLiteHelper.COLOMN_TYPE, type);
 
        long insertId = database.insert(MySQLiteHelper.TABLE_NAME, null, values);
 
        Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME, allColumns,  MySQLiteHelper.PRODUCT_ID +" = "
                + insertId, null, null, null, null);
        cursor.moveToFirst();
 
        return cursorToProduct(cursor);
    }
 
    public List<Product> getAllProducts() {
        List<Product> productsList = new ArrayList<Product>();
        productsList = new ArrayList<Product>();
 
        Cursor cursor = database.query( MySQLiteHelper.TABLE_NAME, allColumns, null, null, null,
                null, null);
        cursor.moveToFirst();
 
        if (cursor.getCount() == 0)
            return productsList;
 
        while (cursor.isAfterLast() == false) {
            Product product = cursorToProduct(cursor);
            productsList.add(product);
            cursor.moveToNext();
        }
 
        cursor.close();
 
        return productsList;
    }
 
    private Product cursorToProduct(Cursor cursor) {
        Product product = new Product();
        product.setId(cursor.getLong(0));
        product.setBarcode(cursor.getString(1));
        product.setType(cursor.getString(2));
 
        return product;
    }
}

Danke euch
 

Anhänge

  • layout1.png
    layout1.png
    12,9 KB · Aufrufe: 25
  • layout3.png
    layout3.png
    26,7 KB · Aufrufe: 28
  • layout2.png
    layout2.png
    21,4 KB · Aufrufe: 30

dzim

Top Contributor
Keine Ahnung. Vielleicht im Bug im Scanner.
Dein Quellcode ist schön und gut, aber weder kann ich hier noch auf deinen Screenshots irgendwo ein Problem sehen.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Reward Ads AdMob wird nicht ausgeliefert. Android & Cross-Platform Mobile Apps 9
J Spinner wird nicht aktualisiert Android & Cross-Platform Mobile Apps 6
Naxon89 Duplicate class kotlin - und dies ohne das es angewendet wird Android & Cross-Platform Mobile Apps 1
ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 4
W Bildschirm Nutzung Überwachen der App Nutzer ink. was angeklickt wird Android & Cross-Platform Mobile Apps 35
N XY-Plottet keine Daten obwohl Funktion ausgeführt wird Android & Cross-Platform Mobile Apps 4
K Null-Pointer-Exception in ListView - wird über Datenbank gefüllt Android & Cross-Platform Mobile Apps 1
R Android Do not disturb: Sound wird nicht abgespielt Android & Cross-Platform Mobile Apps 2
O Google Admob Ad wird nicht geladen und App stürzt ab Android & Cross-Platform Mobile Apps 1
M Paper DB wird in Android Studio nicht erkannt Android & Cross-Platform Mobile Apps 7
R Audio wird nur 1 Mal abgespielt Android & Cross-Platform Mobile Apps 2
A GraphView => X- und Y-Achse wird nicht angezeigt Android & Cross-Platform Mobile Apps 5
A jpg wird im Android Studio nicht akzeptiert Android & Cross-Platform Mobile Apps 3
Arif Android Radiobutton wird nicht deaktiviert Android & Cross-Platform Mobile Apps 1
Arif Android Canvas wird nicht gezeichnet? Android & Cross-Platform Mobile Apps 0
J Notification wird nicht angezeigt wenn App nicht offen ist. Android & Cross-Platform Mobile Apps 6
M TypedArray-Resource wird falsch geladen Android & Cross-Platform Mobile Apps 7
W Preview wird nicht korrekt angezeigt Android & Cross-Platform Mobile Apps 0
B Profilpic wird nach anmeldung nicht angezeigt. Android & Cross-Platform Mobile Apps 2
K Methode wird nicht gefunden Android & Cross-Platform Mobile Apps 1
J Kamera - Foto wird nicht gespeichert Android & Cross-Platform Mobile Apps 2
V Android Wird mein Vorhaben funktionieren? (Apk Datei decompilieren, bearbeiten, compilieren) Android & Cross-Platform Mobile Apps 2
G App wird nach Installation auf Smartphone beendet Android & Cross-Platform Mobile Apps 1
L Dialog anzeigen wenn auf Button gedrückt wird. Android & Cross-Platform Mobile Apps 4
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
O Android Switch Widget wird nicht angezeigt Android & Cross-Platform Mobile Apps 1
M Android ListView wird nicht dargestellt Android & Cross-Platform Mobile Apps 2
P Herausfinden, welches Fragment gerade angezeigt wird. Android & Cross-Platform Mobile Apps 1
M Android Nur erste Zeile wird vom Server empfangen Android & Cross-Platform Mobile Apps 0
A App wird bei start des Timers beendet Android & Cross-Platform Mobile Apps 1
A Wieso wird die App beendet ??? Android & Cross-Platform Mobile Apps 2
B Alle Daten gehen verloren, wenn die Displaysperre aktiviert wird? Android & Cross-Platform Mobile Apps 21
P trotz invalidate() wird onDraw() nicht aufgerufen Android & Cross-Platform Mobile Apps 15
W XML Layout: wann wird geladen? Android & Cross-Platform Mobile Apps 10
K Android Temperaturconverter, R.id.element wird nicht gefunden Android & Cross-Platform Mobile Apps 20
A onDraw wird nicht aufgerufen Android & Cross-Platform Mobile Apps 14
A Android Dialog wird nicht sofort angezeigt Android & Cross-Platform Mobile Apps 12
W ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 19
T Android: ListView-Adapter: Adapter wird ständig aufgerufen Android & Cross-Platform Mobile Apps 2
F Android Datenbank upgrade wird nicht durchgeführt Android & Cross-Platform Mobile Apps 2
F Android R.raw wird nicht gefunden Android & Cross-Platform Mobile Apps 5
P ID wird nicht erzeugt Android & Cross-Platform Mobile Apps 2
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
R Zeichen-Codierung in (SMS) TextMessage, "_" wird § Android & Cross-Platform Mobile Apps 2
AllBlack Auf der Suche nach einem App-Entwickler Android & Cross-Platform Mobile Apps 1
J Android zugrif auf Thread nach Handy drehen. Android & Cross-Platform Mobile Apps 10
AGW App schließt nach 2 Sekunden Android & Cross-Platform Mobile Apps 2
ruutaiokwu Android Daten von "Activity A" nach "Activity B" umleiten? Android & Cross-Platform Mobile Apps 13
A Android-Studio: 2. Layout nach kurzer Zeit aufzeigen Android & Cross-Platform Mobile Apps 2
J BLOB nach dem Download unbrauchbar Android & Cross-Platform Mobile Apps 0
B App schließt nach Start. Android & Cross-Platform Mobile Apps 12
J Android Nach Appsprachenänderung die Systemsprache ermitteln Android & Cross-Platform Mobile Apps 2
B Android wie kann ich in einer xml nach bestimme item suchen (DOM) Android & Cross-Platform Mobile Apps 7
Fischkralle Android Nach Textdateien in Ordner suchen Android & Cross-Platform Mobile Apps 5
V Android Fehlermeldung beim Öffnen von Eclipse nach Installation der Android Erweiterung Android & Cross-Platform Mobile Apps 4
T Android Nach Buttonclick neu laden Android & Cross-Platform Mobile Apps 3
B Android Activity nach gedrückte Returntaste weiterlaufen lassen Android & Cross-Platform Mobile Apps 2
B Android ringProgressDialog nach Erfolg Button einfärben Android & Cross-Platform Mobile Apps 2
L Android Bildschirm bleibt dunkel nach neustarten der App nach betätigen des Home-Buttons Android & Cross-Platform Mobile Apps 3
N Android EditText.setError() funktioniert nicht nach Rotation Android & Cross-Platform Mobile Apps 1
B Android Button erstellen nach Vorlage Android & Cross-Platform Mobile Apps 4
L Android Button mit Pfeil nach rechts Android & Cross-Platform Mobile Apps 1
M Android App startet nach Tastensperre neu Android & Cross-Platform Mobile Apps 3
P Android Nach Animation Layout auf alten Platz Android & Cross-Platform Mobile Apps 3
G Werteübergabe nach unbestimmter Zeit Android & Cross-Platform Mobile Apps 28
A Fehlermeldung nach Neuinstallation von Eclipse/bestehenden Projekten... Android & Cross-Platform Mobile Apps 2
E Android App stürzt nach Modifizierung ab Android & Cross-Platform Mobile Apps 2
N Textview macht immer nach einem Beistrich einen Abstand Android & Cross-Platform Mobile Apps 6
K Apps durchsuchen nach verwendeter Methode Android & Cross-Platform Mobile Apps 4
M Android MediaRecorder - Crash nach 2. Start Android & Cross-Platform Mobile Apps 2
S rms recordstore bleibt nach schießen der anwengung nicht erhalten Android & Cross-Platform Mobile Apps 4
M Text in txt-Datei schreiben und nach ABC sortieren? Android & Cross-Platform Mobile Apps 2
H FileConnection: Frage nach Dateisystem-Zugriff unterdrücken Android & Cross-Platform Mobile Apps 5
K suche nach der richtigen dokumentationh Android & Cross-Platform Mobile Apps 2
S ein String nach vorgegebenen Zeichen teilen Android & Cross-Platform Mobile Apps 3
L Ungültiges Java-Archiv (jar) nach Programmentwicklung Android & Cross-Platform Mobile Apps 4

Ähnliche Java Themen

Neue Themen


Oben