在 android 应用程序中使用它之前我是否必须启动某种 sqlite 服务器
好吧,几乎所有问题都在问题中,我对应该使用 sqlite 的程序有问题,它仍然返回“意外错误”,我只是想知道我是否必须启动某种服务器、守护程序或服务?
androidManifest[ snippet ]
<activity android:name=".About">
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity android:name=".Exit">
andorid:label="@string/exit_title">
</activity>
<activity android:name=".Options">
</activity>
<activity android:name=".Start">
</activity>
<activity android:name=".Create">
</activity>
</application>
AndroidSQLite
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sql);
TextView listContent = (TextView)findViewById(R.id.contentlist);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.deleteAll();
mySQLiteAdapter.insert("ABCDE");
mySQLiteAdapter.insert("FGHIJK");
mySQLiteAdapter.insert("1234567");
mySQLiteAdapter.insert("890");
mySQLiteAdapter.insert("Testing");
mySQLiteAdapter.close();
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
String contentRead = mySQLiteAdapter.queueAll();
mySQLiteAdapter.close();
listContent.setText(contentRead);
}
sql.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>
<ListView
android:id="@+id/contentlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
main.xml [snippet]
<Button
android:id="@+id/where_button"
android:onClick="WhereCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/where_label" />
负责按钮的代码 我在哪里?
mainActivity.java
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View startButton = findViewById(R.id.start_button);
View whereButton = findViewById(R.id.where_button);
View aboutButton = findViewById(R.id.about_button);
View exitButton = findViewById(R.id.exit_button);
}
public void OptionsCl(View v){
startActivity(new Intent(this,Options.class));
}
public void WhereCl(View v){
startActivity(new Intent(this,AndroidSQLite.class));
}
public void StartCl(View v){
Intent idd = new Intent(this,Start.class);
startActivity(idd);
}
public void AboutCl(View v){
startActivity(new Intent(this,About.class));
}
public void ExitCl(View v){
finish();
}
}
我收到的错误与此类似,它提出了未注册的操作,但该操作已注册[检查代码]
它只是“应用程序blabla(menu.dot)已意外停止。请重试”强制关闭。
well, almost everything is in the question, I have a problem with program which should use the sqlite, it still returns the "unexpected error", I was just wondering do I have to start some kind of server, deamon or service?
androidManifest[ snippet ]
<activity android:name=".About">
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity android:name=".Exit">
andorid:label="@string/exit_title">
</activity>
<activity android:name=".Options">
</activity>
<activity android:name=".Start">
</activity>
<activity android:name=".Create">
</activity>
</application>
AndroidSQLite
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sql);
TextView listContent = (TextView)findViewById(R.id.contentlist);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.deleteAll();
mySQLiteAdapter.insert("ABCDE");
mySQLiteAdapter.insert("FGHIJK");
mySQLiteAdapter.insert("1234567");
mySQLiteAdapter.insert("890");
mySQLiteAdapter.insert("Testing");
mySQLiteAdapter.close();
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
String contentRead = mySQLiteAdapter.queueAll();
mySQLiteAdapter.close();
listContent.setText(contentRead);
}
sql.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>
<ListView
android:id="@+id/contentlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
main.xml [snippet]
<Button
android:id="@+id/where_button"
android:onClick="WhereCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/where_label" />
code responsible for button Where Am I?
mainActivity.java
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View startButton = findViewById(R.id.start_button);
View whereButton = findViewById(R.id.where_button);
View aboutButton = findViewById(R.id.about_button);
View exitButton = findViewById(R.id.exit_button);
}
public void OptionsCl(View v){
startActivity(new Intent(this,Options.class));
}
public void WhereCl(View v){
startActivity(new Intent(this,AndroidSQLite.class));
}
public void StartCl(View v){
Intent idd = new Intent(this,Start.class);
startActivity(idd);
}
public void AboutCl(View v){
startActivity(new Intent(this,About.class));
}
public void ExitCl(View v){
finish();
}
}
the error I receive is similar to this which come up with unregistred action, but the action is registred [ check the code ]
it is just "the application blabla (menu.dot) has stopped unexpectedly. Please try again" Force close.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android SQLite 是现成的库。所以你不需要启动任何服务、服务器或恶魔。只是启动一个扩展 SQLite DatabaseHelper 类的数据库类并使用它。
谢谢。
Android SQLite is readymade library. So you don't need to start any Service, server or demon. Just to initiate a database class extending SQLite DatabaseHelper class and use it.
Thanks.