简体   繁体   English

Com.example 路径错误

[英]Com.example path with errors

When I was releasing an apk on google play I had to use a different package name cause of "com.example".当我在 google play 上发布 apk 时,我不得不使用不同的 package 名称,原因是“com.example”。 I tried this and I get crash after testing an application.我试过了,在测试应用程序后我崩溃了。 Before that everything was ok.在此之前一切正常。 I can send a manifest.我可以发送清单。

There are my errors.有我的错误。

呃

My classes我的课程

Details.java详情.java

public class Details extends AppCompatActivity {
NoteDatabase db;
Note note;
TextView mDetails;
TextView clientDetails;
TextView timeDetails;
TextView nameDetails;
TextView detailsDetails;
ImageView noteDetails;




private Bitmap getImageFromByte(byte[] zdjecie){
    return BitmapFactory.decodeByteArray(zdjecie, 0, zdjecie.length);
}



@SuppressLint("WrongThread")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);



    mDetails = findViewById(R.id.detailsOfNote);
    mDetails.setMovementMethod(new ScrollingMovementMethod());
    clientDetails = findViewById(R.id.clientOfNote);
    timeDetails = findViewById(R.id.timeofNote);
    nameDetails = findViewById(R.id.nameOfNote);
    detailsDetails = findViewById(R.id.detailsOfNote);
    noteDetails = findViewById(R.id.noteImage);





    Intent i = getIntent();
    Long id = i.getLongExtra("ID", 0);

    db = new NoteDatabase(this);
    note = db.getNote(id);
    getSupportActionBar().setTitle(note.getTitle());
    

    mDetails.setText(note.getContent());
    clientDetails.setText(note.getTitle());
    timeDetails.setText(note.getTime());
    nameDetails.setText(note.getName());
    detailsDetails.setText(note.getDetails());
    noteDetails.setImageBitmap(stringToImage(note.getImage()));


    Toast.makeText(this, "Podgląd klienta", Toast.LENGTH_SHORT).show();

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            db.deleteNote(note.getID());
            Toast.makeText(getApplicationContext(), "Klient usunięty", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(getApplicationContext(),klienci.class));
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.edit_menu, menu);
    return true;

}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    if(item.getItemId() == R.id.editNote){
        Toast.makeText(this, "Edytowanie notatki", Toast.LENGTH_SHORT).show();
        Intent i = new Intent(this,Edit.class);
        i.putExtra("ID",note.getID());
        startActivity(i);

    }
    return super.onOptionsItemSelected(item);
}

private void goToMain() {
    Intent i = new Intent(this,klienci.class);
    startActivity(i);
}

private Bitmap stringToImage(String imgString){
    byte[] decodedString = Base64.decode(imgString,Base64.DEFAULT);
    Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString,0,decodedString.length);
    return  decodedByte;
}

NoteDatabase.java注意数据库.java

public class NoteDatabase extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 42;
private static final String DATABASE_NAME = "notedbs";
private static final String DATABASE_TABLE = "notestables";

private static final String KEY_ID = "id";
private static final String KEY_TITLE = "title";
private static final String KEY_CONTENT = "content";
private static final String KEY_DATE = "date";
private static final String KEY_TIME = "time";
private static final String KEY_PHONE = "phone";
private static final String KEY_CLIENT = "client";
private static final String KEY_DETAILS = "details";
private static final String KEY_IMAGE = "image";








NoteDatabase(Context context) {
    super(context, DATABASE_NAME,null,DATABASE_VERSION);

}






@Override
public void onCreate(SQLiteDatabase db) {
    String query = "CREATE TABLE "+ DATABASE_TABLE + "("+ KEY_ID+" INT PRIMARY KEY,"+
            KEY_TITLE + " TEXT,"+
            KEY_CONTENT + " TEXT,"+
            KEY_DATE + " TEXT,"+
            KEY_TIME + " TEXT,"+
            KEY_CLIENT + " TEXT,"+
            KEY_DETAILS + " TEXT,"+
            KEY_PHONE + " TEXT,"+
            KEY_IMAGE + " TEXT"+")";
    db.execSQL(query);



}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    if(oldVersion >= newVersion)
        return;
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
    onCreate(db);




}

public long addNote(Note note) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues c = new ContentValues();
    c.put(KEY_TITLE,note.getTitle());
    c.put(KEY_CONTENT,note.getContent());
    c.put(KEY_PHONE,note.getPhone());
    c.put(KEY_CLIENT,note.getClient());
    c.put(KEY_DETAILS,note.getDetails());
    c.put(KEY_DATE,note.getDate());
    c.put(KEY_TIME,note.getTime());
    c.put(KEY_IMAGE,note.getImage());

    long ID = db.insert(DATABASE_TABLE,null, c);
    Log.d("Inserted", "ID -> " + ID);
    return ID;


}



public Note getNote(long id){
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(DATABASE_TABLE,new String[] {KEY_ID,KEY_TITLE,KEY_CONTENT,KEY_PHONE,KEY_CLIENT,KEY_DETAILS,KEY_DATE,KEY_TIME,KEY_IMAGE}, KEY_ID+"=?",

            new String[]{String.valueOf(id)}, null, null,null);
    if (cursor != null)
        cursor.moveToFirst();
    return new Note
            (cursor.getLong(0)
                    ,cursor.getString(1)
                    ,cursor.getString(2)
                    ,cursor.getString(3)
                    ,cursor.getString(4)
                    ,cursor.getString(5)
                    ,cursor.getString(6)
                    ,cursor.getString(7)
                    ,cursor.getString(8));
}



public List<Note> getNotes() {
    SQLiteDatabase db = this.getReadableDatabase();
    List<Note> allNotes = new ArrayList<>();



    String query = "SELECT * FROM " + DATABASE_TABLE + " ORDER BY "+KEY_TITLE+" ASC";
    Cursor cursor = db.rawQuery(query,null);
    if(cursor.moveToFirst()){
        do{
            Note note = new Note();
            note.setID(cursor.getLong(0));
            note.setTitle(cursor.getString(1));
            note.setDetails(cursor.getString(2));
            note.setPhone(cursor.getString(3));
            note.setClient(cursor.getString(4));
            note.setContent(cursor.getString(5));
            note.setDate(cursor.getString(6));
            note.setTime(cursor.getString(7));
            note.setImage(cursor.getString(8));



            allNotes.add(note);


        }while(cursor.moveToNext());

    }

    return allNotes;

}


public int editNote(Note note){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues c = new ContentValues();
    Log.d("Edited", "Edited Title: -> "+ note.getTitle() + "\n ID -> "+note.getZdjecie());
    c.put(KEY_TITLE,note.getTitle());
    c.put(KEY_CONTENT,note.getContent());
    c.put(KEY_PHONE,note.getPhone());
    c.put(KEY_CLIENT,note.getClient());
    c.put(KEY_DETAILS,note.getDetails());
    c.put(KEY_DATE,note.getDate());
    c.put(KEY_TIME,note.getTime());
    c.put(KEY_IMAGE,note.getImage());
    return db.update(DATABASE_TABLE,c,KEY_ID +"=?",new String[]{String.valueOf(note.getID())});
}

void deleteNote(long id) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(DATABASE_TABLE, KEY_ID + "=?", new String[]{String.valueOf(id)});
    db.close();
}

You are trying to get 0 index in the database.您正在尝试在数据库中获取 0 索引。 Every time you add a new Note its ID will be 0. So, change your database KEY_ID to AUTOINCREMENT.每次添加新的 Note 时,它的 ID 都将为 0。因此,将数据库KEY_ID更改为 AUTOINCREMENT。

String query = "CREATE TABLE " + DATABASE_TABLE + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                KEY_TITLE + " TEXT," +
                KEY_CONTENT + " TEXT," +
                KEY_DATE + " TEXT," +
                KEY_TIME + " TEXT," +
                KEY_PIES + " TEXT," +
                KEY_RASAPSA + " TEXT," +
                KEY_TEL + " TEXT," +
                KEY_ZDJECIE + " TEXT" + ")";
        db.execSQL(query);

Then check your cursor not null in然后检查您的 cursor 而不是 null

getNote()获取笔记()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入com.example无法解析 - The import com.example cannot be resolved java.lang.IllegalArgumentException:未知的URL内容://com.example - java.lang.IllegalArgumentException: Unknown URL content://com.example 如何在Scala中使用Java包com.example ...对象 - How to use Java package com.example…object in Scala Android Studio 2016重命名com.example文件错误 - Android Studio 2016 renaming com.example file error java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMap无法强制转换为com.example - java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.example “无法启动活动ComponentInfo {com.example / com.artifex.mupdfdemo.MuPDFActivity}:java.lang.NullPointerException” - “Unable to start activity ComponentInfo{com.example/com.artifex.mupdfdemo.MuPDFActivity}: java.lang.NullPointerException” com.example:demo:0.0.1-SNAPSHOT的不可解析的父POM - Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT “com.example 受限”谷歌播放错误; 即使更改包名称 - “com.example restricted” Google Play error; even when changing the package name 我收到此错误:无法将java String类型的对象转换为com.example类型 - i get this error : Can't convert object of type java String to type com.example 包'com.example'从'javafx.base'和'javafx.base'中读取包'javafx.beans' - Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM