在 android 应用程序中使用它之前我是否必须启动某种 sqlite 服务器

发布于 2024-12-11 19:16:46 字数 2998 浏览 0 评论 0原文

好吧,几乎所有问题都在问题中,我对应该使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦途 2024-12-18 19:16:46

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文