2014-01-19 4 views
-1

디버깅 방법을 알아야합니다. Android 앱 강제 종료

01-19 17:36:09.206: E/AndroidRuntime(487): FATAL EXCEPTION: main 
    01-19 17:36:09.206: E/AndroidRuntime(487): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.aoutsu/com.example.aoutsu.AddNewItem}; have you declared this activity in your AndroidManifest.xml? 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.app.Activity.startActivityForResult(Activity.java:2827) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.app.Activity.startActivity(Activity.java:2933) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at com.example.aoutsu.HomePage$1.onClick(HomePage.java:50) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.view.View.performClick(View.java:2485) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.view.View$PerformClick.run(View.java:9080) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.os.Handler.handleCallback(Handler.java:587) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.os.Handler.dispatchMessage(Handler.java:92) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.os.Looper.loop(Looper.java:123) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at android.app.ActivityThread.main(ActivityThread.java:3683) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at java.lang.reflect.Method.invokeNative(Native Method) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at java.lang.reflect.Method.invoke(Method.java:507) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
    01-19 17:36:09.206: E/AndroidRuntime(487): at dalvik.system.NativeStart.main(Native Method) 

이 내 AddNewItem.java

package com.example.aoutsu; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.ContentValues; 
import android.content.DialogInterface; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 

public class AddNewItem extends Activity implements OnClickListener{ 

    private Button btn_save; 
    private EditText edit_name,edit_desc,edit_quantity; 
    private DbHelper mHelper; 
    private SQLiteDatabase dataBase; 
    private String id,name,desc,quantity; 
    private boolean isUpdate; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.add_item); 

      btn_save=(Button)findViewById(R.id.save_btn); 
      edit_name=(EditText)findViewById(R.id.item_name); 
      edit_desc=(EditText)findViewById(R.id.item_desc); 
      edit_quantity=(EditText)findViewById(R.id.Quantity); 
      isUpdate=getIntent().getExtras().getBoolean("update"); 
      if(isUpdate) 
      { 
       id=getIntent().getExtras().getString("ID"); 
       name=getIntent().getExtras().getString("ItemName"); 
       desc=getIntent().getExtras().getString("ItemDesc"); 
       quantity=getIntent().getExtras().getString("Quantity"); 
       edit_name.setText(name); 
       edit_desc.setText(desc); 
       edit_quantity.setText(quantity); 

      } 

      btn_save.setOnClickListener(this); 

      mHelper=new DbHelper(this); 

     } 

     // saveButton click event 
     public void onClick(View v) { 
      name=edit_name.getText().toString().trim(); 
      desc=edit_desc.getText().toString().trim(); 
      quantity=edit_quantity.getText().toString().trim(); 
      if(name.length()>0 && desc.length()>0 && quantity.length()>0) 
      { 
       saveData(); 
      } 
      else 
      { 
       AlertDialog.Builder alertBuilder=new AlertDialog.Builder(AddNewItem.this); 
       alertBuilder.setTitle("Invalid Data"); 
       alertBuilder.setMessage("Please, Enter valid data"); 
       alertBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 

        public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 

        } 
       }); 
       alertBuilder.create().show(); 
      } 

     } 

     /** 
     * save data into SQLite 
     */ 
     private void saveData(){ 
      dataBase=mHelper.getWritableDatabase(); 
      ContentValues values=new ContentValues(); 

      values.put(DbHelper.KEY_ITEMNAME,name); 
      values.put(DbHelper.KEY_ITEMDESC,desc); 
      values.put(DbHelper.KEY_ITEMQUANTITY,quantity); 

      System.out.println(""); 
      if(isUpdate) 
      {  
       //update database with new data 
       dataBase.update(DbHelper.TABLE_NAME, values, DbHelper.KEY_ID+"="+id, null); 
      } 
      else 
      { 
       //insert data into database 
       dataBase.insert(DbHelper.TABLE_NAME, null, values); 
      } 
      //close database 
      dataBase.close(); 
      finish(); 


     } 

    } 

내 Homepage.java

package com.example.aoutsu; 

import java.util.ArrayList; 




import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.AdapterView; 
import android.widget.ListView; 
import android.widget.Toast; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.AdapterView.OnItemLongClickListener; 

public class HomePage extends Activity { 
    private DbHelper mHelper; 
    private SQLiteDatabase dataBase; 

    private ArrayList<String> item_id = new ArrayList<String>(); 
    private ArrayList<String> name_item = new ArrayList<String>(); 
    private ArrayList<String> desc_item = new ArrayList<String>(); 
    private ArrayList<String> quantity = new ArrayList<String>(); 

    private ListView itemList; 
    private AlertDialog.Builder build; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home_page); 
     itemList = (ListView) findViewById(R.id.listView); 

     mHelper = new DbHelper(this); 
     findViewById(R.id.addBtn).setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 

       Intent i = new Intent(getApplicationContext(), 
         AddNewItem.class); 
       i.putExtra("update", false); 
       startActivity(i); 

      } 
     }); 

     //click to update data 
     itemList.setOnItemClickListener(new OnItemClickListener() { 

      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
        long arg3) { 

       Intent i = new Intent(getApplicationContext(), 
         AddNewItem.class); 
       i.putExtra("ItemName", name_item.get(arg2)); 
       i.putExtra("ItemDesc", desc_item.get(arg2)); 
       i.putExtra("Quantity", quantity.get(arg2)); 
       i.putExtra("ID", item_id.get(arg2)); 
       i.putExtra("update", true); 
       startActivity(i); 
      } 
     }); 



    //long click to delete data 
    itemList.setOnItemLongClickListener(new OnItemLongClickListener() { 

     public boolean onItemLongClick(AdapterView<?> arg0, View arg1, 
       final int arg2, long arg3) { 

      build = new AlertDialog.Builder(HomePage.this); 
      build.setTitle("Delete " + name_item.get(arg2) + " " 
        + desc_item.get(arg2) + quantity.get(arg2)); 
      build.setMessage("Do you want to delete ?"); 
      build.setPositiveButton("Yes", 
        new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, 
           int which) { 

          Toast.makeText(
            getApplicationContext(), 
            name_item.get(arg2) + " " 
              + desc_item.get(arg2) +" " + quantity.get(arg2) 
              + " is deleted.", 3000).show(); 

          dataBase.delete(
            DbHelper.TABLE_NAME, 
            DbHelper.KEY_ID + "=" 
              + item_id.get(arg2), null); 
          displayData(); 
          dialog.cancel(); 
         } 
        }); 

      build.setNegativeButton("No", 
        new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, 
           int which) { 
          dialog.cancel(); 
         } 
        }); 
      AlertDialog alert = build.create(); 
      alert.show(); 

      return true; 
     } 
    }); 
} 

@Override 
    protected void onResume() { 
    displayData(); 
    super.onResume(); 
    } 

/** 
* displays data from SQLite 
*/ 
    private void displayData() { 
    dataBase = mHelper.getWritableDatabase(); 
    Cursor mCursor = dataBase.rawQuery("SELECT * FROM " 
      + DbHelper.TABLE_NAME, null); 

    item_id.clear(); 
    name_item.clear(); 
    desc_item.clear(); 
    quantity.clear(); 
    if (mCursor.moveToFirst()) { 
     do { 
      item_id.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ID))); 
      name_item.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ITEMNAME))); 
      desc_item.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ITEMDESC))); 
      quantity.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ITEMQUANTITY))); 

     } while (mCursor.moveToNext()); 
    } 
    DisplayAdapter disadpt = new DisplayAdapter(HomePage.this,item_id, name_item, desc_item,quantity); 
    itemList.setAdapter(disadpt); 
    mCursor.close(); 
} 


} 

입니다 이것은 내 DbHelper.java

package com.example.aoutsu; 

import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
/** 
* sqlite database helper to create table into SQLite database 
* @author ketan(Visit my <a 
*   href="http://androidsolution4u.blogspot.in/">blog</a>) 
*/ 
public class DbHelper extends SQLiteOpenHelper { 
    static String DATABASE_NAME="example_db"; 
    public static final String TABLE_NAME="inventory_db"; 
    public static final String KEY_ITEMNAME="itemname"; 
    public static final String KEY_ITEMDESC="itemdesc"; 
    public static final String KEY_ITEMQUANTITY="itemquantity"; 
    public static final String KEY_ID="id"; 
    public DbHelper(Context context) { 
     super(context, DATABASE_NAME, null, 1); 

    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+" ("+KEY_ID+" INTEGER PRIMARY KEY, "+KEY_ITEMNAME+" TEXT, "+KEY_ITEMDESC+" TEXT, "+KEY_ITEMQUANTITY+ "TEXT)"; 
     db.execSQL(CREATE_TABLE); 

    } 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME); 
     onCreate(db); 

    } 

} 

이며,이 내입니다 DisplayAdapter.java

package com.example.aoutsu; 

import java.util.ArrayList; 

import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.TextView; 


public class DisplayAdapter extends BaseAdapter{ 
     private Context mContext; 
     private ArrayList<String> id; 
     private ArrayList<String> item; 
     private ArrayList<String> description; 
     private ArrayList<String> quantity; 


     public DisplayAdapter(Context c, ArrayList<String> id,ArrayList<String> itemname, ArrayList<String> itemdesc, ArrayList<String> itemquantity) { 
      this.mContext = c; 
      this.id = id; 
      this.item = itemname; 
      this.description = itemdesc; 
      this.quantity = itemquantity; 
     } 

     public int getCount() { 
      // TODO Auto-generated method stub 
      return id.size(); 
     } 

     public Object getItem(int position) { 
      // TODO Auto-generated method stub 
      return null; 
     } 

     public long getItemId(int position) { 
      // TODO Auto-generated method stub 
      return 0; 
     } 

     public View getView(int pos, View child, ViewGroup parent) { 
      Holder mHolder; 
      LayoutInflater layoutInflater; 
      if (child == null) { 
       layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       child = layoutInflater.inflate(R.layout.listcell, null); 
       mHolder = new Holder(); 
       mHolder.txt_id = (TextView) child.findViewById(R.id.txt_id); 
       mHolder.txt_N = (TextView) child.findViewById(R.id.txt_name); 
       mHolder.txt_D = (TextView) child.findViewById(R.id.txt_desc); 
       mHolder.txt_Q = (TextView) child.findViewById(R.id.txt_quantity); 
       child.setTag(mHolder); 
      } else { 
       mHolder = (Holder) child.getTag(); 
      } 
      mHolder.txt_id.setText(id.get(pos)); 
      mHolder.txt_N.setText(item.get(pos)); 
      mHolder.txt_D.setText(description.get(pos)); 
      mHolder.txt_Q.setText(quantity.get(pos)); 

      return child; 
     } 

     public class Holder { 
      TextView txt_id; 
      TextView txt_N; 
      TextView txt_D; 
      TextView txt_Q; 
     } 

    } 
+1

매니페스트 파일에서 활동 선언이 누락 된 것 같습니다. Androidmanifest.xml의 내용 추가 – PravinCG

+0

이전에 비슷한 질문을하지 않으셨습니까? – Raghunandan

+1

당신의 logcat에'AddNewItem'에 대한'ActivityNotFoundException'이 있습니다, 당신의 AndroidManifest.xml에서이 활동을 선언 했습니까? –

답변

2

문제는 안드로이드 그래서 그 중 하나 이상이 적용 com.example.aoutsu.AddNewItem라는 방법을 찾을 수 있다는 것입니다 :

1) 클래스 com.example.aoutsu이 정의되어 있지 않습니다.

2) 사용자가를 잘못 호출했습니다.이상이어야합니다.

3) AndroidManifest.xml 파일에서이 활동을 정의하지 않았습니다.

그런데 예외를 디버깅하려면 항상 파일을 참조하는 행을 찾으십시오. 이 경우 :

01-19 17:36:09.206: E/AndroidRuntime(487): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.aoutsu/com.example.aoutsu.AddNewItem}; have you declared this activity in your AndroidManifest.xml? 

그 다음 Google 애널리틱스에이 텍스트를 넣으면됩니다. 이전에 수천 명의 사용자가 있었던 것을 찾으십시오.

0

그냥 activty 매니페스트 파일 -에 AddNewItem를 선언

<activity android:name=".AddNewItem" ></activity>