我的项目有问题。当我点击SQLiteDatabase
按钮时,我的应用程序将在手机上崩溃。 “搜索”按钮是一种从package com.example.taza.rshinventorymanager;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Homepage extends AppCompatActivity
{
TextView locationoutput, quantityoutput, size1output, size2output, size3output,
size4output, size5output, size6output, size7output, size8output, size9output,
size10output, size11output, size12output, size13output, sizeXSoutput, sizeSoutput,
sizeMoutput, sizeLoutput, sizeXLoutput, size2XLoutput;
EditText searchproduct;
ProductDBHelper productDBHelper;
SQLiteDatabase sqLiteDatabase;
String Searchproduct;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
Button LoginButton = (Button)findViewById(R.id.HomepageLoginButton);
LoginButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent startIntent = new Intent(getApplicationContext(), LoginPage.class);
startActivity(startIntent);
}
});
searchproduct = (EditText)findViewById(R.id.HomepageET);
locationoutput = (TextView)findViewById(R.id.HPLocation);
quantityoutput = (TextView)findViewById(R.id.HPQuantity);
size1output = (TextView)findViewById(R.id.HP1);
size2output = (TextView)findViewById(R.id.HP2);
size3output = (TextView)findViewById(R.id.HP3);
size4output = (TextView)findViewById(R.id.HP4);
size5output = (TextView)findViewById(R.id.HP5);
size6output = (TextView)findViewById(R.id.HP6);
size7output = (TextView)findViewById(R.id.HP7);
size8output = (TextView)findViewById(R.id.HP8);
size9output = (TextView)findViewById(R.id.HP9);
size10output = (TextView)findViewById(R.id.HP10);
size11output = (TextView)findViewById(R.id.HP11);
size12output = (TextView)findViewById(R.id.HP12);
size13output = (TextView)findViewById(R.id.HP13);
sizeXSoutput = (TextView)findViewById(R.id.HPXS);
sizeSoutput = (TextView)findViewById(R.id.HPS);
sizeMoutput = (TextView)findViewById(R.id.HPM);
sizeLoutput = (TextView)findViewById(R.id.HPL);
sizeXLoutput = (TextView)findViewById(R.id.HPXL);
size2XLoutput = (TextView)findViewById(R.id.HP2XL);
locationoutput.setVisibility(View.GONE);
quantityoutput.setVisibility(View.GONE);
size1output.setVisibility(View.GONE);
size1output.setVisibility(View.GONE);
size2output.setVisibility(View.GONE);
size3output.setVisibility(View.GONE);
size4output.setVisibility(View.GONE);
size5output.setVisibility(View.GONE);
size6output.setVisibility(View.GONE);
size7output.setVisibility(View.GONE);
size8output.setVisibility(View.GONE);
size9output.setVisibility(View.GONE);
size10output.setVisibility(View.GONE);
size11output.setVisibility(View.GONE);
size12output.setVisibility(View.GONE);
size13output.setVisibility(View.GONE);
sizeXSoutput.setVisibility(View.GONE);
sizeSoutput.setVisibility(View.GONE);
sizeMoutput.setVisibility(View.GONE);
sizeLoutput.setVisibility(View.GONE);
sizeXLoutput.setVisibility(View.GONE);
size2XLoutput.setVisibility(View.GONE);
}
public void SearchProduct (View view)
{
Searchproduct = searchproduct.getText().toString();
productDBHelper = new ProductDBHelper(getApplicationContext());
sqLiteDatabase = productDBHelper.getReadableDatabase();
Cursor cursor = productDBHelper.getProduct(Searchproduct, sqLiteDatabase);
if(cursor.moveToFirst())
{
String locationsearch = cursor.getString(0);
String quantitysearch = cursor.getString(1);
String size1search = cursor.getString(2);
String size2search = cursor.getString(3);
String size3search = cursor.getString(4);
String size4search = cursor.getString(5);
String size5search = cursor.getString(6);
String size6search = cursor.getString(7);
String size7search = cursor.getString(8);
String size8search = cursor.getString(9);
String size9search = cursor.getString(10);
String size10search = cursor.getString(11);
String size11search = cursor.getString(12);
String size12search = cursor.getString(13);
String size13search = cursor.getString(14);
String sizeXSsearch = cursor.getString(15);
String sizeSsearch = cursor.getString(16);
String sizeMsearch = cursor.getString(17);
String sizeLsearch = cursor.getString(18);
String sizeXLsearch = cursor.getString(19);
String size2XLsearch = cursor.getString(20);
locationoutput.setText(locationsearch);
quantityoutput.setText(quantitysearch);
size1output.setText(size1search);
size2output.setText(size2search);
size3output.setText(size3search);
size4output.setText(size4search);
size5output.setText(size5search);
size6output.setText(size6search);
size7output.setText(size7search);
size8output.setText(size8search);
size9output.setText(size9search);
size10output.setText(size10search);
size11output.setText(size11search);
size12output.setText(size12search);
size13output.setText(size13search);
sizeXSoutput.setText(sizeXSsearch);
sizeSoutput.setText(sizeSsearch);
sizeMoutput.setText(sizeMsearch);
sizeLoutput.setText(sizeLsearch);
sizeXLoutput.setText(sizeXLsearch);
size2XLoutput.setText(size2XLsearch);
locationoutput.setVisibility(View.VISIBLE);
quantityoutput.setVisibility(View.VISIBLE);
size1output.setVisibility(View.VISIBLE);
size1output.setVisibility(View.VISIBLE);
size2output.setVisibility(View.VISIBLE);
size3output.setVisibility(View.VISIBLE);
size4output.setVisibility(View.VISIBLE);
size5output.setVisibility(View.VISIBLE);
size6output.setVisibility(View.VISIBLE);
size7output.setVisibility(View.VISIBLE);
size8output.setVisibility(View.VISIBLE);
size9output.setVisibility(View.VISIBLE);
size10output.setVisibility(View.VISIBLE);
size11output.setVisibility(View.VISIBLE);
size12output.setVisibility(View.VISIBLE);
size13output.setVisibility(View.VISIBLE);
sizeXSoutput.setVisibility(View.VISIBLE);
sizeSoutput.setVisibility(View.VISIBLE);
sizeMoutput.setVisibility(View.VISIBLE);
sizeLoutput.setVisibility(View.VISIBLE);
sizeXLoutput.setVisibility(View.VISIBLE);
size2XLoutput.setVisibility(View.VISIBLE);
}
}
}
检索信息的方法。此活动是Where子句活动。每当我点击“搜索”按钮时,它就会崩溃。
这是我的编码:
01-24 12:07:21.692 3720-3720/? E/DATABASE OPERATIONS: Database created / opened...
01-24 12:07:21.695 3720-3720/? E/SQLiteLog: (1) near "TABLEproduct_information": syntax error
01-24 12:07:21.695 3720-3720/? D/AndroidRuntime: Shutting down VM
01-24 12:07:21.696 3720-3720/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.taza.rshinventorymanager, PID: 3720
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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.database.sqlite.SQLiteException: near "TABLEproduct_information": syntax error (code 1): , while compiling: CREATE TABLEproduct_information(product_codeTEXT,product_locationTEXT,product_quantityTEXT,size_1TEXT,size_2TEXT,size_3TEXT,size_4TEXT,size_5TEXT,size_6TEXT,size_7TEXT,size_8TEXT,size_9TEXT,size_10TEXT,size_11TEXT,size_12TEXT,size_13TEXT,size_XSTEXT,size_STEXT,size_MTEXT,size_LTEXT,size_XLTEXT,size_2XLTEXT)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at com.example.taza.rshinventorymanager.ProductDBHelper.onCreate(ProductDBHelper.java:52)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
at com.example.taza.rshinventorymanager.Homepage.SearchProduct(Homepage.java:101)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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)
我调试后发现了Logcat。这是错误:
set := {
{ 'age'->'25'. 'code'->'2512' } asDictionary .
{ 'age'->'40'. 'code'->'1243' } asDictionary.
{ 'age'->'35'. 'code'->'7854' } asDictionary.
} asSet.
答案 0 :(得分:0)
您正在 onCreate
中编写 onClick 方法max-age