这是我用过的代码.我想为数据库添加一个名称.当我在EditText中输入名称时,它接受,当我单击提交按钮时,它会显示消息"App_name已经停止不幸"activity_main.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="70dp"
android:text="USERNAME"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="28dp"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="50dp"
android:text="SUBMIT" />
</RelativeLayout>`
Run Code Online (Sandbox Code Playgroud)
Main_Activity.java
package com.example.dbconcept;
import android.os.Bundle;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
Button b;
String user;
EditText usr;
SQLiteDatabase db;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
try{
db=openOrCreateDatabase("Mydb",MODE_PRIVATE,null);
db.execSQL("create …Run Code Online (Sandbox Code Playgroud) main()
{
char a[20];
int b;
printf("\n enter your name");
a[20]=getchar();
printf("\n enter your password");
scanf("%d",&b);
if (a=="ilangeeran")
{
printf("\n login successful");
}
}
Run Code Online (Sandbox Code Playgroud)
这是示例程序,在编译此堆栈时发生粉碎错误如何解决此错误?