我正在开始使用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);

}}


活动Manifest.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>


记录

 E / Trace(1454):打开跟踪文件时出错:没有这样的文件或目录(2)
 D / dalvikvm(1454):newInstance失败:否()
 D / AndroidRuntime(1454):关闭VM
 W / dalvikvm(1454):threadid = 1:线程以未捕获的异常退出(group = 0x40a71930)
 E / AndroidRuntime(1454):致命异常:主要
 E / AndroidRuntime(1454):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.example.examplebase / com.example.examplebase.Ebase}:java.lang.InstantiationException:无法实例化com.example.examplebase类.ebase;没有空的构造函数
 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.invokeNative(本机方法)
 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.Ebase类;没有空的构造函数
 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个

最佳答案

您更正后的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.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>


希望这应该工作

07-27 15:57