Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLite没有空构造函数_Android_Sqlite - Fatal编程技术网

Android SQLite没有空构造函数

Android SQLite没有空构造函数,android,sqlite,Android,Sqlite,我正在开始使用Android。我想创建一个数据库。但是日志显示错误:我的服务没有空构造函数。我不能添加任何空构造函数。一定是我做错了什么。但是我找不到它。请帮帮我 MainActivity.java: public class Ebase extends SQLiteOpenHelper { private static final String BOOKS = "book.db"; private static final int Version = 1; public Ebase(Con

我正在开始使用Android。我想创建一个数据库。但是日志显示错误:我的服务没有空构造函数。我不能添加任何空构造函数。一定是我做错了什么。但是我找不到它。请帮帮我

MainActivity.java:

public class Ebase extends SQLiteOpenHelper {

private static final String BOOKS = "book.db";
private static final int Version = 1;

public Ebase(Context con) {
    super(con, BOOKS, null, Version);

}

public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE" + "btable"
            + "(bNum TEXT, pName TEXT, price INTEGER, quantity INTEGER )");

}

public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
    db.execSQL("DROP TABLE IF EXIST btable");
    onCreate(db);

}}
我的另一节课

public class Ebase2 extends Activity {

public Ebase book;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ebase);

    book = new Ebase(this);

    final EditText bnumber = (EditText) findViewById(R.id.editText1);
    Button search = (Button) findViewById(R.id.button1);
    search.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            try {
                DataSearch((bnumber.getText()).toString());

            } finally {
                book.close();
            }

        }
    });

}

private static final String[] SELECT = { "bNum" };

protected void DataSearch(String string) {
    SQLiteDatabase db = book.getReadableDatabase();
    Cursor c = db.query("btable", SELECT, null, null, null, null, null);
    while (c.moveToNext()) {
        if (c.toString() == string)
            GettingData(c);

    }

}

private void GettingData(Cursor c) {
    StringBuilder builder = new StringBuilder("Information\n");
    String pName = c.getString(c.getColumnIndex("pName"));
    String price = c.getString(c.getColumnIndex("price"));
    String quantity = c.getString(c.getColumnIndex("quantity"));
    builder.append(pName).append("Product Name:");
    builder.append(price).append("Price:");
    builder.append(quantity).append("Quantity:");

    TextView result = (TextView) findViewById(R.id.textView1);

}}
活动清单.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examplebase"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.examplebase.Ebase"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:label="@string/app_name"  android:name="Ebase2"/>
</application></manifest>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examplebase"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.examplebase.Ebase2"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application></manifest>

日志

E/Trace(1454):打开跟踪文件时出错:没有这样的文件或目录(2) D/dalvikvm(1454):新实例失败:否() D/AndroidRuntime(1454):关闭虚拟机 W/dalvikvm(1454):threadid=1:线程以未捕获异常退出(组=0x40a71930) E/AndroidRuntime(1454):致命异常:主 E/AndroidRuntime(1454):java.lang.RuntimeException:无法实例化活动组件信息{com.example.examplebase/com.example.examplebase}:java.lang.InstanceException:无法实例化类com.example.examplebase;没有空构造函数 E/AndroidRuntime(1454):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106) E/AndroidRuntime(1454):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) E/AndroidRuntime(1454):位于android.app.ActivityThread.access$600(ActivityThread.java:141) E/AndroidRuntime(1454):位于android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) E/AndroidRuntime(1454):位于android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(1454):位于android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(1454):位于android.app.ActivityThread.main(ActivityThread.java:5041) E/AndroidRuntime(1454):位于java.lang.reflect.Method.Invokenactive(本机方法) E/AndroidRuntime(1454):位于java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime(1454):位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) E/AndroidRuntime(1454):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) E/AndroidRuntime(1454):位于dalvik.system.NativeStart.main(本机方法) E/AndroidRuntime(1454):原因:java.lang.InstantiationException:无法实例化类com.example.examplebase;没有空构造函数 E/AndroidRuntime(1454):位于java.lang.Class.newInstanceImpl(本机方法) E/AndroidRuntime(1454):位于java.lang.Class.newInstance(Class.java:1319) E/AndroidRuntime(1454):位于android.app.Instrumentation.newActivity(Instrumentation.java:1054) E/AndroidRuntime(1454):位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
E/AndroidRuntime(1454):。。。11更多您将
Ebase
声明为XML中的一个活动,但是
Ebase
派生自
SQLiteOpenHelper
,它根本不实现
活动。我猜您是想将
Ebase2
放在第一个
声明中(在这种情况下,删除第二个
声明)。

您更正的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examplebase"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.examplebase.Ebase"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:label="@string/app_name"  android:name="Ebase2"/>
</application></manifest>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examplebase"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.examplebase.Ebase2"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application></manifest>


希望这能起作用

我认为您应该在ebase类中添加以下代码:

public Ebase() {

}

把你的日志信息放在我的服务上?你到底得到了什么错误?@PankajKumar我添加了日志消息。@PiotrChojnacki我得到了类似“无空构造函数”的错误。这不会有什么区别。