0

我对此并不陌生,并且不断遇到相同的错误。请帮帮我。这是我的主要活动类,我已经搜索了很多页面,尝试了很多次,但得到了同样的错误。无法捕捉到错误

public class SQLiteExample extends Activity {
    LinearLayout Linear;
    SQLiteDatabase mydb;
    private static String DBNAME = "PERSONS.db";    // THIS IS THE SQLITE DATABASE FILE NAME.
    private static String TABLE = "MY_TABLE";       // THIS IS THE TABLE NAME

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sqlite_example);
        Linear  = (LinearLayout)findViewById(R.id.linear);
        Toast.makeText(getApplicationContext(), "Creating table.", Toast.LENGTH_SHORT).show();

        dropTable();        // DROPPING THE TABLE.
        createTable();
        TextView t0 = new TextView(this);
        t0.setText("This tutorial covers CREATION, INSERTION, UPDATION AND DELETION USING SQLITE DATABASES.                                                Creating table complete........");
        Linear.addView(t0);
        Toast.makeText(getApplicationContext(), "Creating table complete.", Toast.LENGTH_SHORT).show();
        insertIntoTable();
        TextView t1 = new TextView(this);
        t1.setText("Insert into table complete........");
        Linear.addView(t1);
        Toast.makeText(getApplicationContext(), "Insert into table complete", Toast.LENGTH_SHORT).show();
        TextView t2 = new TextView(this);
        t2.setText("Showing table values............");
        Linear.addView(t2);
        showTableValues();
        Toast.makeText(getApplicationContext(), "Showing table values", Toast.LENGTH_SHORT).show();
        updateTable();
        TextView t3 = new TextView(this);
        t3.setText("Updating table values............");
        Linear.addView(t3);
        Toast.makeText(getApplicationContext(), "Updating table values", Toast.LENGTH_SHORT).show();
        TextView t4 = new TextView(this);
        t4.setText("Showing table values after updation..........");
        Linear.addView(t4);
        Toast.makeText(getApplicationContext(), "Showing table values after updation.", Toast.LENGTH_SHORT).show();
        showTableValues();
        deleteValues();
        TextView t5 = new TextView(this);
        t5.setText("Deleting table values..........");
        Linear.addView(t5);
        Toast.makeText(getApplicationContext(), "Deleting table values", Toast.LENGTH_SHORT).show();
        TextView t6 = new TextView(this);
        t6.setText("Showing table values after deletion.........");
        Linear.addView(t6);
        Toast.makeText(getApplicationContext(), "Showing table values after deletion.", Toast.LENGTH_SHORT).show();
        showTableValues();
        setColor(t0);
        setColor(t1);
        setColor(t2);
        setColor(t3);
        setColor(t4);
        setColor(t5);
        setColor(t6);
    }
    // THIS FUNCTION SETS COLOR AND PADDING FOR THE TEXTVIEWS 
    public void setColor(TextView t){
        t.setTextColor(Color.BLACK);
        t.setPadding(20, 5, 0, 5);
        t.setTextSize(1, 15);
    }

    // CREATE TABLE IF NOT EXISTS 
    public void createTable(){
        try{
        mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        mydb.execSQL("CREATE TABLE IF  NOT EXISTS "+ TABLE +" (ID INTEGER PRIMARY KEY, NAME TEXT, PLACE TEXT);");
        mydb.close();
        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG);
        }
    }
    // THIS FUNCTION INSERTS DATA TO THE DATABASE
    public void insertIntoTable(){
        try{
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('CODERZHEAVEN','GREAT INDIA')");
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('ANTHONY','USA')");
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('SHUING','JAPAN')");
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('JAMES','INDIA')");
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('SOORYA','INDIA')");
            mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('MALIK','INDIA')");
            mydb.close();
        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG);
        }
    }
    // THIS FUNCTION SHOWS DATA FROM THE DATABASE 
    public void showTableValues(){
        try{
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
            Cursor allrows  = mydb.rawQuery("SELECT * FROM "+  TABLE, null);
            System.out.println("COUNT : " + allrows.getCount());
            Integer cindex = allrows.getColumnIndex("NAME");
            Integer cindex1 = allrows.getColumnIndex("PLACE");

            TextView t = new TextView(this);
            t.setText("========================================");
            //Linear.removeAllViews();
            Linear.addView(t);

            if(allrows.moveToFirst()){
                do{
                    LinearLayout id_row   = new LinearLayout(this);
                    LinearLayout name_row = new LinearLayout(this);
                    LinearLayout place_row= new LinearLayout(this);

                    final TextView id_  = new TextView(this);
                    final TextView name_ = new TextView(this);
                    final TextView place_ = new TextView(this);
                    final TextView   sep  = new TextView(this);

                    String ID = allrows.getString(0);
                    String NAME= allrows.getString(1);
                    String PLACE= allrows.getString(2);

                    id_.setTextColor(Color.RED);
                    id_.setPadding(20, 5, 0, 5);
                    name_.setTextColor(Color.RED);
                    name_.setPadding(20, 5, 0, 5);
                    place_.setTextColor(Color.RED);
                    place_.setPadding(20, 5, 0, 5);

                    System.out.println("NAME " + allrows.getString(cindex) + " PLACE : "+ allrows.getString(cindex1));
                    System.out.println("ID : "+ ID  + " || NAME " + NAME + "|| PLACE : "+ PLACE);

                    id_.setText("ID : " + ID);
                    id_row.addView(id_);
                    Linear.addView(id_row);
                    name_.setText("NAME : "+NAME);
                    name_row.addView(name_);
                    Linear.addView(name_row);
                    place_.setText("PLACE : " + PLACE);
                    place_row.addView(place_);
                    Linear.addView(place_row);
                    sep.setText("---------------------------------------------------------------");
                    Linear.addView(sep);
                }
                while(allrows.moveToNext());
            }
            mydb.close();
         }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error encountered.", Toast.LENGTH_LONG);
        }
    }
    // THIS FUNCTION UPDATES THE DATABASE ACCORDING TO THE CONDITION 
    public void updateTable(){
        try{
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
            mydb.execSQL("UPDATE " + TABLE + " SET NAME = 'MAX' WHERE PLACE = 'USA'");
            mydb.close();
        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error encountered", Toast.LENGTH_LONG);
        }
    }
    // THIS FUNCTION DELETES VALUES FROM THE DATABASE ACCORDING TO THE CONDITION
    public void deleteValues(){
        try{
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
            mydb.execSQL("DELETE FROM " + TABLE + " WHERE PLACE = 'USA'");
            mydb.close();
        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error encountered while deleting.", Toast.LENGTH_LONG);
        }
    }
    // THIS FUNCTION DROPS A TABLE 
    public void dropTable(){
        try{
            mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
            mydb.execSQL("DROP TABLE " + TABLE);
            mydb.close();
        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "Error encountered while dropping.", Toast.LENGTH_LONG);
        }
    }
}

日志猫

09-10 11:14:18.432: E/Trace(1310): error opening trace file: No such file or directory (2)
09-10 11:14:19.671: D/AndroidRuntime(1310): Shutting down VM
09-10 11:14:19.671: W/dalvikvm(1310): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-10 11:14:19.742: E/AndroidRuntime(1310): FATAL EXCEPTION: main
09-10 11:14:19.742: E/AndroidRuntime(1310): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sqlite/com.sqlite.SQLiteExample}: android.view.InflateException: Binary XML file line #6: Error inflating class android.widget.ScrollView
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.os.Looper.loop(Looper.java:137)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at java.lang.reflect.Method.invokeNative(Native Method)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at java.lang.reflect.Method.invoke(Method.java:511)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at dalvik.system.NativeStart.main(Native Method)
09-10 11:14:19.742: E/AndroidRuntime(1310): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.widget.ScrollView
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.Activity.setContentView(Activity.java:1881)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at com.sqlite.SQLiteExample.onCreate(SQLiteExample.java:25)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.Activity.performCreate(Activity.java:5104)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-10 11:14:19.742: E/AndroidRuntime(1310):     ... 11 more
09-10 11:14:19.742: E/AndroidRuntime(1310): Caused by: java.lang.reflect.InvocationTargetException
09-10 11:14:19.742: E/AndroidRuntime(1310):     at java.lang.reflect.Constructor.constructNative(Native Method)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
09-10 11:14:19.742: E/AndroidRuntime(1310):     ... 24 more
09-10 11:14:19.742: E/AndroidRuntime(1310): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f020001}
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.content.res.Resources.loadDrawable(Resources.java:1927)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.View.<init>(View.java:3330)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.view.ViewGroup.<init>(ViewGroup.java:431)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.widget.FrameLayout.<init>(FrameLayout.java:101)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.widget.ScrollView.<init>(ScrollView.java:161)
09-10 11:14:19.742: E/AndroidRuntime(1310):     at android.widget.ScrollView.<init>(ScrollView.java:157)
09-10 11:14:19.742: E/AndroidRuntime(1310):     ... 27 more
09-10 11:14:19.761: D/dalvikvm(1310): GC_CONCURRENT freed 80K, 7% free 2812K/3016K, paused 21ms+31ms, total 167ms

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sqlite"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@+drawable/icon" android:label="@string/app_name">
        <activity android:name=".SQLiteExample"
                  android:label="SQLite Example Demo">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

activity_sqlite_example.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@+drawable/android">
            <LinearLayout
                android:id="@+id/linear"
                android:orientation="vertical"
                android:layout_below="@+id/add_record"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent">
            </LinearLayout>
    </ScrollView>
</LinearLayout>
4

3 回答 3

0

我认为你在这里做错了android:background="@+drawable/android"

删除“+”并使用类似的东西

  <ScrollView
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/android">
于 2013-09-10T11:33:05.447 回答
0
  1. 从 中删除+android:background

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@+drawable/android">
    

    将其更改为

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/android">
    
  2. 确保图像/可绘制对象存在于相应的文件夹中。

于 2013-09-10T11:32:37.030 回答
0

在您的 xml 中,您已经给出了android:background="@+drawable/android". 我想应该是

android:background="@drawable/android" . 

确保您的 android drawable 存在于所需的 drawable 文件夹中。该错误也清楚地表明了由以下原因引起的问题:android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f020001}

于 2013-09-10T11:32:48.220 回答