0

我在 android 版本 4.2 中有一个示例应用程序。我为每一行设置了断点。在调试的时候,突然调试停止说“源附件不包含文件SQLiteOpenHelper.class的源”。

我附上了jar文件,它仍然报告错误。当前安装了所有东西。但不知道这个错误的原因。

这是我的 MainActivity.java

package com.example.newwaterreadingapp;


import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;



public class MainActivity extends Activity {

protected static final android.content.Context Context = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.activity_main);

    final RelativeLayout mainLayout=(RelativeLayout)findViewById(R.id.mainLayout);
    mainLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
    final LinearLayout readingLayout=(LinearLayout)findViewById(R.id.waterReading);
    readingLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
    final LinearLayout pastDatePickerLayout=(LinearLayout)findViewById(R.id.PastDatePickerLayout);
    pastDatePickerLayout.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
    readingLayout.setVisibility(View.GONE);
    pastDatePickerLayout.setVisibility(View.GONE);


    Button AddWaterReading=(Button)findViewById(R.id.AddWaterReading);    //click on + button.
    AddWaterReading.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            readingLayout.setVisibility(View.VISIBLE);
            mainLayout.setVisibility(View.GONE);
            TextView txtgetCurrentDate=(TextView)findViewById(R.id.currentDate);
            final Calendar c=Calendar.getInstance();
            txtgetCurrentDate.setText((c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.DATE)+"/"+c.get(Calendar.YEAR));  

        }
    });

    TextView getPastDate=(TextView)findViewById(R.id.getDate);
    getPastDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            readingLayout.setVisibility(View.GONE);
            pastDatePickerLayout.setVisibility(View.VISIBLE);                           
        }
    });

    Button savePastDate=(Button)findViewById(R.id.savePastDate);
    savePastDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            pastDatePickerLayout.setVisibility(View.GONE);
            readingLayout.setVisibility(View.VISIBLE);

            DatePicker getPastDatepicker=(DatePicker)findViewById(R.id.getPastDate);
                int YY=getPastDatepicker.getYear();
                int MM=getPastDatepicker.getMonth();
                int DD=getPastDatepicker.getDayOfMonth();
                TextView getPastDate=(TextView)findViewById(R.id.getDate);  
                getPastDate.setText((MM+1)+"/"+DD+"/"+YY);
        }
    });


    Button saveWaterReadingToDB=(Button)findViewById(R.id.saveWaterReading);
    saveWaterReadingToDB.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            readingLayout.setVisibility(View.GONE);
             mainLayout.setVisibility(View.VISIBLE);    

             TextView getPastDate=(TextView)findViewById(R.id.getDate);
             TextView txtgetCurrentDate=(TextView)findViewById(R.id.currentDate);
             TextView txtgetWaterReading=(TextView)findViewById(R.id.water_Reading);


             CreateDB helper =new CreateDB(Context, "WaterElectricityReading.db", null, 1);              

             SQLiteDatabase DB;

             DB=helper.getWritableDatabase();

             String pastDate=getPastDate.getText().toString().trim();
             String currentDate=txtgetCurrentDate.getText().toString().trim();
             String waterReading=txtgetWaterReading.getText().toString().trim();


             ContentValues values=new ContentValues();
             values.put(CreateDB.COLUMN_NAME_READING_MODE,"Water");
             values.put(CreateDB.COLUMN_NAME_PASTDATETIME, pastDate);
             values.put(CreateDB.COLUMN_NAME_CURRENTDATETIME, currentDate);
             values.put(CreateDB.COLUMN_NAME_READINGVALUE, waterReading);

             DB.insert(CreateDB.TABLE_NAME, null, values);
             Toast.makeText(getApplicationContext(), "Added", Toast.LENGTH_LONG).show();
             DB.close();
             helper.close();                 
        }
    });

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

和 CreateDB.java

package com.example.newwaterreadingapp;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;



public class CreateDB extends SQLiteOpenHelper{

    private static final String DATABASE_NAME="WaterElectricityReading.db";
    public static final String TABLE_NAME="Reading";
    public static final String COLUMN_NAME_READING_ID="_Id";
    public static final String COLUMN_NAME_READING_MODE="ReadingMode";
    public static final String COLUMN_NAME_PASTDATETIME="PastDateTime";
    public static final String COLUMN_NAME_CURRENTDATETIME="CurrentDateTime";
    public static final String COLUMN_NAME_READINGVALUE="ReadingValue";
    public static final int DATABASE_VERSION = 1;
     public static String DB_PATH = "";


    public CreateDB(Context context,String name, CursorFactory factory,
            int version) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);                                  
    }

    public void onCreate(SQLiteDatabase DB){

        final String CREATE_TABLE="create table if not exists "+ TABLE_NAME + "("+ COLUMN_NAME_READING_ID +" integer primary key autoincrement,"
                +COLUMN_NAME_READING_MODE+" text not null,"+COLUMN_NAME_PASTDATETIME+" date not null,"+COLUMN_NAME_CURRENTDATETIME
                +" date not null,"+COLUMN_NAME_READINGVALUE+" integer not null"+");";
        DB.execSQL(CREATE_TABLE);                                                       

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }           

}

谁能建议我哪里出错了。

谢谢。

4

1 回答 1

1

.jar 本身不会公开其源代码。您必须自己添加源代码才能浏览它。

你可以很确定错误是在你自己的一方,所以你可以质疑调试 Android 代码的使用:)

您可以手动添加它(不记得如何,Google)或使用过去对我做得很好的 Eclipse 插件;https://code.google.com/p/adt-addons/ 可能有点过时了。

于 2013-03-04T07:50:17.260 回答