如何更正项目中无法打开堆栈跟踪文件?

时间:2011-11-28 09:15:25

标签: android android-widget android-manifest

我正在尝试调试我的课程项目。然而,大部分工作都是有效的,我的检查数据和快速保存按钮(意外停止)。我在调试会话中的一个错误是无法打开堆栈跟踪文件。那是什么意思?我查看了一些有关该主题的旧问题,并为我的清单添加了权限。我的代码已附上。当我尝试点击这些按钮时,试图弄清楚为什么我没有发生..(检查数据)和(保存)...也许如果有人可以运行代码并在手机上查看。我真的处于停止点......项目附加...下面,Main,CheckData,SaveData,Data Manipulator java文件......和xml文件 谢谢,...非常感谢任何建议...

Main.java
 package com.terrellmcqueen.databaseproject5;
 import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 public class Main extends Activity implements OnClickListener {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    View button1Click = findViewById(R.id.button1);
    button1Click.setOnClickListener(this);
    View button2Click = findViewById(R.id.button2);
    button2Click.setOnClickListener(this);        
  }
 @Override
 public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
        case R.id.button1:
            Intent i = new Intent(this, SaveData.class);  
            startActivity(i);
        break;
        case R.id.button2:
            Intent i1 = new Intent(this, CheckData.class);  
            startActivity(i1);
        break;
    }
}

}

      CheckData.java
    package com.terrellmcqueen.databaseproject5;
    import java.util.ArrayList;
    import java.util.List;

    import android.app.ListActivity;
    import android.os.Bundle;
     import android.view.View;
   import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.TextView;
  public class CheckData extends ListActivity  {     
   TextView selection;
   public int idToModify; 
   DataManipulator dm;
   List<String[]> list = new ArrayList<String[]>();
   List<String[]> names2 =null ;
  String[] stg1;
   protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check);
    dm = new DataManipulator(this);
    names2 = dm.selectAll();
    stg1=new String[names2.size()]; 
    int x=0;
    String stg;
    for (String[] name : names2) {
            stg = name[1]+" – "+name[2]+ " – "+name[3]+" – "+name[4];
            stg1[x]=stg;
            x++;
      }
       ArrayAdapter<String> adapter = new ArrayAdapter<String>                                (        this, andoid.R.layout.simple_list_item_1,stg1);
    this.setListAdapter(adapter);
    selection=(TextView)findViewById(R.id.selection);
   }      
     public void onListItemClick(ListView parent, View v, int position, long id) {
    selection.setText(stg1[position]);
     }
         }

     SaveData.java 

   package com.terrellmcqueen.databaseproject5;

   import android.app.Activity;
   import android.app.AlertDialog;
   import android.app.Dialog;
   import android.content.DialogInterface;
    import android.content.Intent;
    import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.EditText;
   import android.widget.TextView;
    public class SaveData extends Activity implements OnClickListener {  
private static final int REQUEST_BARCODE = 0;
private TextView mbarcodeEdit;
private DataManipulator dh;     
   static final int DIALOG_ID = 0;
   protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.save);
    mbarcodeEdit = (EditText) findViewById(R.id.mbarCodeEdit);
    View scan = findViewById(R.id.Scan1);
    scan.setOnClickListener(this);
    View add = findViewById(R.id.Button01add);
    add.setOnClickListener(this);
    View home = findViewById(R.id.Button01home);
    home.setOnClickListener(this);           
      }
     public void onClick(View v){
    switch(v.getId()){

        case R.id.Scan1:
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "SCAN_MODE");
        startActivityForResult(intent, REQUEST_BARCODE);


     /** public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       if (requestCode == REQUEST_BARCODE) {
            if (resultCode == RESULT_OK) {
        String barcode = intent.getStringExtra("SCAN_RESULT");
               mbarcodeEdit.setText(barcode);
                } else if (resultCode == RESULT_CANCELED) {
                    finish();
                } 
            }
       };*/

         //  public void onClick1(View v) {
         // switch(v.getId()){
          break;
          case R.id.Button01home:
            Intent i = new Intent(this, SaveData.class);
            startActivity(i);
        break;
        case R.id.Button01add:
            View editText1 = (EditText) findViewById(R.id.mbarCodeEdit);
            View editText2 = (EditText) findViewById(R.id.assetType);
            View editText3 = (EditText) findViewById(R.id.description);
            View editText4 = (EditText) findViewById(R.id.Make); 
            String myEditText1=((TextView) editText1).getText().toString();
            String myEditText2=((TextView) editText2).getText().toString();
            String myEditText3=((TextView) editText3).getText().toString();
            String myEditText4=((TextView) editText4).getText().toString();
            this.dh = new DataManipulator(this);
            this.dh.insert(myEditText1,myEditText2,myEditText3,myEditText4);
            showDialog(DIALOG_ID);
           break;
        };
         }

        public void onActivityResult(int requestCode, int resultCode, Intent intent) {
            if (requestCode == REQUEST_BARCODE) {
                 if (resultCode == RESULT_OK) {
             String barcode = intent.getStringExtra("SCAN_RESULT");
                    mbarcodeEdit.setText(barcode);
                     } else if (resultCode == RESULT_CANCELED) {
                         finish();
                     } 
                 }
                    };
              protected final Dialog onCreateDialog(final int id) {
           Dialog dialog = null;
          switch(id) {
            case DIALOG_ID:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Information saved successfully ! 
             Add Another   Info?").setCancelable(false).setPositiveButton
            ("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                            SaveData.this.finish();
                    }
            }).setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                    }
            });
            AlertDialog alert = builder.create(); 
            dialog = alert;
            break;
             default:
               }
                     return dialog;    
                    }
                   }`


         DataManipulator.java


           package com.terrellmcqueen.databaseproject5;


           import java.util.ArrayList;
          import java.util.List;

         import android.content.Context;
         import android.database.Cursor;
          import android.database.sqlite.SQLiteDatabase;
          import android.database.sqlite.SQLiteOpenHelper;
           import android.database.sqlite.SQLiteStatement;
         public class DataManipulator
           {
          private static final  String DATABASE_NAME = "mydatabase.db";
          private static final int DATABASE_VERSION = 1;
        static final String TABLE_NAME = "newtable";
      private static Context context;
     static SQLiteDatabase db;
     private SQLiteStatement insertStmt;

        private static final String                                                                
          INSERT = "insert                                       
    into " + TABLE_NAME + "      (barcode,type,description,make) values (?,?,?,?)"; 
     public DataManipulator(Context context) {
    DataManipulator.context = context;
    OpenHelper openHelper = new OpenHelper(DataManipulator.context);
    DataManipulator.db = openHelper.getWritableDatabase();
    this.insertStmt = DataManipulator.db.compileStatement(INSERT);
     }
    public long insert(String barcode,String type,String description,String make) {
    this.insertStmt.bindString(1, barcode);
    this.insertStmt.bindString(2, type);
    this.insertStmt.bindString(3, description);
    this.insertStmt.bindString(4, make);
    return this.insertStmt.executeInsert();
    }
     public void deleteAll() {
    db.delete(TABLE_NAME, null, null);
    }
    public List<String[]> selectAll()
    {
    List<String[]> list = new ArrayList<String[]>();
       Cursor cursor = db.query(TABLE_NAME, 
     new String[] {    "id","barcode","type","description","make" }, 
       null, null, null, null, "name asc"); 
    int x=0;
    if (cursor.moveToFirst()) {
       do {
            String[] b1=new 
          String[] {cursor.getString(0),cursor.getString(1),cursor.getString(2),
         cursor.getString(3),cursor.getString(4)};
            list.add(b1);
            x=x+1;
       } while (cursor.moveToNext());
    }
    if (cursor != null && !cursor.isClosed()) {
       cursor.close();
    } 
    cursor.close();
    return list;
         }
       public void delete(int rowId) {
        db.delete(TABLE_NAME, null, null); 
           }
    private static class OpenHelper extends SQLiteOpenHelper {
    OpenHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
         db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER 
    PRIMARY KEY, barcode  INTEGER, tpye TEXT, description TEXT, make TEXT)");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {
         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
         onCreate(db);
    }
   }
     }

 Main.xml
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

 <TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="DataBase Sample App"
    android:textSize="24.5sp" />

  <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/text"
    android:layout_marginLeft="34dp"
    android:layout_marginTop="74dp"
    android:text="Check Data" />

  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button2"
    android:layout_alignBottom="@+id/button2"
    android:layout_alignRight="@+id/text"
    android:text="Save Data" />

   </RelativeLayout>

 Save.xml
 <?xml version="1.0" encoding="UTF-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/LinearLayout01"
 android:layout_width="wrap_content"
  android:layout_height="wrap_content"
 android:orientation="vertical"
 android:paddingLeft="20sp" >

   <TextView
    android:id="@+id/button1_label"
    android:layout_width="wrap_content"
     android:layout_height="fill_parent"
    android:layout_marginBottom="25dip"
    android:text="Asset Information Form"
    android:textSize="15.5sp" />

  <Button
    android:id="@+id/Scan1"
    android:layout_width="142dp"
    android:layout_height="wrap_content"
    android:text="Scanner" />

  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="BarCode:"
    android:textSize="14.5sp" />
 <EditText
    android:id="@+id/mbarCodeEdit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
   <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Asset_Type:"
    android:textSize="14.5sp" />
  <EditText
    android:id="@+id/assetType"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Asset Description:"
    android:textSize="14.5sp" />
  <EditText
    android:id="@+id/description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
  <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Make/Model:"
    android:textSize="14.5sp" />
  <EditText
    android:id="@+id/Make"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
  <LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="2.22"
    android:orientation="horizontal"
    android:paddingLeft="20sp" >
    <Button
        android:id="@+id/Button01add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20sp"
        android:layout_marginTop="20sp"
        android:text="Save" />
    <Button
        android:id="@+id/Button01home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20sp"
        android:layout_marginTop="20sp"
        android:text="Back" />
     </LinearLayout>
   </LinearLayout>


     Check.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">
<TextView android:id="@+id/selection2" android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="BarCode – Asset Type –         Description- Make/Model" />
<TextView android:id="@+id/selection" android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:drawSelectorOnTop="false"
    android:textSize="3dip" />
      </LinearLayout>


      Manifest file
     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.terrellmcqueen.databaseproject5"
     android:versionCode="1"
     android:versionName="1.0" >


      <uses-sdk android:minSdkVersion="7" />

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name=".Main" >
        <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=".CheckData" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />



    <activity android:label="@string/app_name" 
          android:name=".DataManipulator"   />




    <activity android:label="@string/app_name" android:name=".SaveData" />



             </application>

          </manifest>

0 个答案:

没有答案