我正在研究我的项目应用程序,以了解更多关于Android应用程序开发过程的信息。我正在学习一个在线教程,但我似乎遇到了一个SQLite数据库的错误。它编译得很好,但它一运行就强制关闭。下面是logcat输出:
05-04 12:33:21.980 4403-4403/? I/art: Late-enabling -Xcheck:jni
05-04 12:33:22.177 4403-4403/com.example.a1713500104_crudsqlite_9 W/ActivityThread: Application com.example.a1713500104_crudsqlite_9 is waiting for the debugger on port 8100...
05-04 12:33:22.187 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: Sending WAIT chunk
05-04 12:33:22.594 4403-4410/com.example.a1713500104_crudsqlite_9 I/art: Debugger is active
05-04 12:33:22.792 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: Debugger has connected
05-04 12:33:22.792 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:23.014 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:23.216 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:23.417 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:23.617 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:23.817 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:24.018 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:24.218 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:24.418 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:24.619 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: waiting for debugger to settle...
05-04 12:33:24.820 4403-4403/com.example.a1713500104_crudsqlite_9 I/System.out: debugger has settled (1454)
05-04 12:33:25.079 4403-4403/com.example.a1713500104_crudsqlite_9 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-04 12:33:25.130 4403-4403/com.example.a1713500104_crudsqlite_9 I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
05-04 12:33:25.130 4403-4403/com.example.a1713500104_crudsqlite_9 I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
05-04 12:33:25.188 4403-4403/com.example.a1713500104_crudsqlite_9 W/ResourceType: Failure getting entry for 0x7f06005a (t=5 e=90) (error -75)
05-04 12:33:25.188 4403-4403/com.example.a1713500104_crudsqlite_9 D/AndroidRuntime: Shutting down VM
05-04 12:33:25.190 4403-4403/com.example.a1713500104_crudsqlite_9 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a1713500104_crudsqlite_9, PID: 4403
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a1713500104_crudsqlite_9/com.example.a1713500104_crudsqlite_9.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5305)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.a1713500104_crudsqlite_9.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5305)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.a1713500104_crudsqlite_9:drawable/icontambah" (7f06005a) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f06005a a=-1 r=0x7f06005a}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)
at android.content.res.Resources.loadDrawable(Resources.java:2381)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.widget.TextView.<init>(TextView.java:837)
at android.widget.Button.<init>(Button.java:111)
at android.widget.Button.<init>(Button.java:107)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:71)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:67)
at androidx.appcompat.app.AppCompatViewInflater.createButton(AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:110)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.a1713500104_crudsqlite_9.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5305)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-04 12:33:39.356 4403-4403/com.example.a1713500104_crudsqlite_9 I/Process: Sending signal. PID: 4403 SIG: 9
package com.example.a1713500104_crudsqlite_9;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DbConfig extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "biodatamahasiswa.db";
private static final int DATABASE_VERSION = 1;
public DbConfig (Context context) {
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table biodata (no integer primary key,nama text null,tgl text null,jk text null,alamat text null)";
Log.d("Data","OnCreate: "+sql);
db.execSQL(sql);
sql = "INSERT INTO biodata (no,nama,tgl,jk,alamat) VALUES ('1','Aulia Azmi','1998-07-14','Laki-Laki','Petamburan','Jakarta')";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
}
}
MainActivity.java:
package com.example.a1713500104_crudsqlite_9;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity<item> extends AppCompatActivity {
String[] daftar;
ListView Listview01;
Menu menu;
protected Cursor cursor;
DbConfig dbcenter;
public static MainActivity ma;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg1) {
Intent inte = new Intent(MainActivity.this,BuatBiodataActivity.class);
startActivity(inte);
}
});
ma = this;
dbcenter = new DbConfig(this);
RefreshList();
}
public void RefreshList() {
SQLiteDatabase db = dbcenter.getReadableDatabase();
cursor = db.rawQuery("SELECT*FROM BIODATA",null);
daftar = new String[cursor.getCount()];
cursor.moveToFirst();
for (int cc = 0;cc<cursor.getCount();cc++) {
cursor.moveToPosition(cc);
daftar[cc] = cursor.getString(1).toString();
}
Listview01 = (ListView) findViewById(R.id.listView1);
Listview01.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,daftar));
Listview01.setSelected(true);
Listview01.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
final String selection = daftar[arg2];
final CharSequence[] dialogitem = {"Lihat Biodata","Update Biodata","Hapus Biodata"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Pilihan");
builder.setItems(dialogitem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0:
Intent i = new Intent(getApplicationContext(),LihatBiodataActivity.class);
i.putExtra("nama",selection);
startActivity(i);
break;
case 1:
Intent in = new Intent(getApplicationContext(),UpdateBiodataActivity.class);
in.putExtra("nama",selection);
startActivity(in);
break;
case 2:
SQLiteDatabase db = dbcenter.getWritableDatabase();
db.execSQL("delete from biodata where nama='"+selection+"'");
RefreshList();
break;
}
}
});
builder.create().show();
}
});
((ArrayAdapter) Listview01.getAdapter()).notifyDataSetInvalidated();
}
}
buatbiodataactivity.java
package com.example.a1713500104_crudsqlite_9;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class BuatBiodataActivity extends AppCompatActivity {
protected Cursor cursor;
DbConfig dbHelper;
Button ton1,ton2;
EditText text1,text2,text3,text4,text5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buat_biodata);
dbHelper = new DbConfig(this);
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
text3 = (EditText) findViewById(R.id.editText3);
text4 = (EditText) findViewById(R.id.editText4);
text5 = (EditText) findViewById(R.id.editText5);
ton1 = (Button) findViewById(R.id.button1);
ton2 = (Button) findViewById(R.id.button2);
ton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.execSQL("insert into biodata(no,nama,tgl,jk,alamat)values('"+
text1.getText().toString()+"','"+
text2.getText().toString()+"','"+
text3.getText().toString()+"','"+
text4.getText().toString()+"','"+
text5.getText().toString()+"')");
Toast.makeText(getApplicationContext(), "Berhasil", Toast.LENGTH_SHORT).show();
MainActivity.ma.RefreshList();
finish();
}
});
ton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
lihatBioDataActivity.java
package com.example.a1713500104_crudsqlite_9;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class LihatBiodataActivity extends AppCompatActivity {
protected Cursor cursor;
DbConfig dbHelper;
Button ton2;
TextView text1,text2,text3,text4,text5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lihat_biodata);
dbHelper = new DbConfig(this);
text1 = (TextView) findViewById(R.id.textView1);
text2 = (TextView) findViewById(R.id.textView2);
text3 = (TextView) findViewById(R.id.textView3);
text4 = (TextView) findViewById(R.id.textView4);
text5 = (TextView) findViewById(R.id.textView5);
SQLiteDatabase db = dbHelper.getReadableDatabase();
cursor = db.rawQuery("SELECT*FROM biodata WHERE nama='"+getIntent().getStringExtra("nama")
+"'",null);
cursor.moveToFirst();
if (cursor.getCount()>0) {
cursor.moveToPosition(0);
text1.setText(cursor.getString(0).toString());
text2.setText(cursor.getString(1).toString());
text3.setText(cursor.getString(2).toString());
text4.setText(cursor.getString(3).toString());
text5.setText(cursor.getString(4).toString());
}
ton2 = (Button) findViewById(R.id.button1);
ton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
UpdateBioDataActivity.java
package com.example.a1713500104_crudsqlite_9;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class UpdateBiodataActivity extends AppCompatActivity {
protected Cursor cursor;
DbConfig dbHelper;
Button ton1, ton2;
EditText text1, text2, text3, text4, text5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_biodata);
dbHelper = new DbConfig(this);
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
text3 = (EditText) findViewById(R.id.editText3);
text4 = (EditText) findViewById(R.id.editText4);
text5 = (EditText) findViewById(R.id.editText5);
final SQLiteDatabase db = dbHelper.getReadableDatabase();
cursor = db.rawQuery("SELECT*FROM biodata WHERE nama='" + getIntent().getStringExtra("nama") +
"'", null);
cursor.moveToFirst();
if (cursor.getCount()>0){
cursor.moveToPosition(0);
text1.setText(cursor.getString(0).toString());
text2.setText(cursor.getString(1).toString());
text3.setText(cursor.getString(2).toString());
text4.setText(cursor.getString(3).toString());
text5.setText(cursor.getString(4).toString());
}
ton1 = (Button) findViewById(R.id.button1);
ton2 = (Button) findViewById(R.id.button2);
ton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
db.execSQL("update biodata set nama='" +
text2.getText().toString() + "',tgl='" +
text3.getText().toString() + "',jk='" +
text4.getText().toString() + "',alamat='" +
text5.getText().toString() + "'where no='" +
text1.getText().toString() + "'");
Toast.makeText(getApplicationContext(), "Berhasil", Toast.LENGTH_LONG).show();
MainActivity.ma.RefreshList();
finish();
}
});
ton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
如果有人能帮我找到代码中的错误并提出修复建议,我将不胜感激!事先非常感谢你帮助了像我这样的一个noob:)
您应该在MainActivity.java
中将按钮定义为类字段。
String[] daftar;
ListView Listview01;
Menu menu;
protected Cursor cursor;
DbConfig dbcenter;
public static MainActivity ma;
Button btn; // <------
在oncreate
方法中,为其分配一个对象。
btn = (Button) findViewById(R.id.button2);
通常,要关闭Android设备的电源,当然要通过电源按钮。 您还可以执行和。 但在Android系统中,我看不到关闭设备的方法。如果没问题的话,我很想把树莓圆周率的功率切断,但这可以接受吗?它会损坏SD卡吗?
我今天一直在谷歌上搜索,但什么也找不到。我的场景如下: 我有一个Android应用程序可以自动回复收到的消息。我有下面的代码来创建一个持久的(不可刷的)通知,然后当应用程序通过onDestroy被销毁时,通知被移除。然而,当我打开recents面板并将我的应用程序扫走时,应用程序会停止自动回复服务,广播接收器也会停止,但onDestroy没有被调用,通知仍然可见。 我想简单地销毁通知,如果应用程序
问题内容: 这是我第一次尝试在我的应用中添加广告。我已阅读在线文档并逐字阅读。现在,我唯一不了解的部分是如何实际请求广告并将其添加到我的应用中。 到目前为止,这似乎很好。我要做的其他任何事情都将被迫关闭。例如,添加以下行: 我已将AdListener实现到Activity。 顺便说一句,当我将鼠标悬停在导入的类上时: 或其他类似的类,它表示:注意:该元素既没有附加源,也没有附加Javadoc,因此
问题内容: 我已经能够在我的应用程序中成功实现“共享首选项”,但是如果我通过任务管理器杀死该应用程序,就会遇到重置/删除数据的问题。 我使用的是静态方法进行保存,因此我只需要使用一次该方法,就可以在我的应用程序中的任何地方调用它。 一旦我杀死了我的应用程序,我的所有数据都将恢复为SharedPreferences保存方法中的默认设置。 我也进行了一些搜索,发现一些帖子说将android:persi
构建一个基本的基于sqlite的登录/注册应用程序。点击登录后App崩溃。 有什么想法吗? databaseHelper.java: display.java: contact.java:
问题内容: 我有一个sqlite数据库,其中包含以下格式的基本天气信息: 我如何使用绘制这些数据?在能够绘制数据之前,我必须重新整理数据吗? 问题答案: 要从sqlite数据库中提取数据,您可以使用命令行工具即时提取数据。使用gnuplot可以做到这一点,方法是使用a 生成外壳并使用给定的shell命令的输出进行绘图。 这将为每个图提取所有四个字段(重复先前的文件名/ shell命令)。您还可以使