Android应用程序在模拟器中打开后崩溃

问题描述 投票:0回答:2

我的问题是:当我尝试在模拟器中运行应用程序时,我的应用程序崩溃,我真的不知道问题是什么...下面是我的qazxsw poi类,qazxsw poi,qazxsw poi和logcat crashlog。

MainActivity类:

MainActivity

activity_main.xml中:

androidManifest.xml

AndroidManifest.xml中:

activity_main.xml

Logcat错误日志:

package com.example.notepadapp;

import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

private ArrayList<Aantekening> aantekeningen;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Stelt de nieuwe toolbar in
    Toolbar toolbar = findViewById(R.id.custom_toolbar);
    setSupportActionBar(toolbar);

    // Verkrijg de aantekeningen van de database en stel de ListView adapter in
    final DatabaseHandler db = new DatabaseHandler(getApplicationContext());
    aantekeningen = db.getAllNotes();
    ImageButton newEntry = findViewById(R.id.add);
    ListView mylist = findViewById(R.id.notepad_listview);
    final NotepadAdapter notepadAdapter = new NotepadAdapter(this, aantekeningen);
    mylist.setAdapter(notepadAdapter);

    // Stelt de onClick listener methode in welke de NoteActivity activiteit start
    newEntry.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent addNoteActivity = new Intent(MainActivity.this, NoteActivity.class);
            addNoteActivity.putExtra("Optie", "toevoegen");
            startActivity(addNoteActivity);
        }
    });

    //onItemClick (KORT) in ListView start een NoteActivity
    mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            sendEditIntent(position);
        }
    });

    // Stelt de lange onClick listener om verwijdering toe te staan
    //TODO Maak onClickLongListener methode af...
    mylist.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            // Inflate view
            PopupMenu popup = new PopupMenu(MainActivity.this, view);
            popup.getMenuInflater().inflate(R.menu.note_select_menu, popup.getMenu());
            popup.setGravity(Gravity.END);

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {

                    // Verkrijg geselcteerde titel
                    switch (menuItem.getItemId()) {
                        case R.id.menuEdit:
                            sendEditIntent(position);
                            break;

                        case R.id.menuDelete:
                            db.deleteNote(aantekeningen.get(position).getId());
                            aantekeningen.remove(position);
                            notepadAdapter.notifyDataSetChanged();
                            break;

                            default:
                                break;
                    }

                    return false;
                }
            });

            popup.show();
            return true;
        }
    });
}

/**
 * @param position  positie van item dat is aangeklikt.
 *                  updateNoteActivity wordt gestart.
 */
private void sendEditIntent(int position) {
    Intent updateNoteActivity = new Intent(MainActivity.this, NoteActivity.class);
    updateNoteActivity.putExtra("optie", "bijwerken");
    updateNoteActivity.putExtra("id", aantekeningen.get(position).getId());
    updateNoteActivity.putExtra("naam", aantekeningen.get(position).getNaam());
    updateNoteActivity.putExtra("aantekening", aantekeningen.get(position).getAantekening());
    startActivity(updateNoteActivity);
}
}

可能导致这些错误的问题是什么?

我的<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <!--Aangepaste toolbar--> <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/custom_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" android:theme="@style/customToolbar"> <!-- Tekst zit in Strings.xml bestand in res map --> <!-- Knop om een nieuw taak (ListView Item) toe te voegen --> <ImageButton android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:layout_marginEnd="15dp" android:src="@drawable/ic_add" android:background="@drawable/button_background" android:contentDescription="@string/add_note" /> </android.support.v7.widget.Toolbar> <!-- ListView welke is toegevoegd m.b.v. onClick methode --> <ListView android:id="@+id/notepad_listview" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> 是用荷兰语写的。对不起,如果这是一个问题

java android android-studio crash emulation
2个回答
0
投票

请仔细阅读例外情况。错误是由您的样式主题引起的。

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.notepadapp / com.example.notepadapp.MainActivity}:java.lang.IllegalStateException:此Activity已有窗口装饰提供的操作栏。不要在主题中请求Window.FEATURE_SUPPORT_ACTION_BAR并将windowActionBar设置为false以使用工具栏。

这意味着你必须使用NoActionBar主题。只需转到styles.xml文件并更改Apptheme即可。


0
投票

styles.xml文件有一个名为AppTheme的标签。您选择的父主题提供了一个操作栏。

如果要使用工具栏,则需要使用NoActionBar主题。这是一个好主意。

© www.soinside.com 2019 - 2024. All rights reserved.