无法识别启动活动,未找到默认活动启动活动时出错

Posted

技术标签:

【中文标题】无法识别启动活动,未找到默认活动启动活动时出错【英文标题】:Could not identify launch activity , Default Activity not found Error while Launching activity 【发布时间】:2017-01-28 09:02:50 【问题描述】:

启动我的活动时似乎出现错误;未找到默认活动。代码如下:

清单代码在这里

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"

>     package="com.example.devnagi.callblocke">
> 
> 
>     <uses-permission android:name="android.permission.CALL_PHONE" />
>     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
>     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
> 
> 
> 
> 
> [enter image description here][1]
>     <uses-sdk
>         android:minSdkVersion="14"
>         android:targetSdkVersion="24" />
> 
> 
> 
>         <receiver  android:name=".CallBarring">
>             <intent-filter  android:priority="100" >
>                 <action android:name="android.intent.action.PHONE_STATE" />
>             </intent-filter>
>         </receiver>
> 
>     <!--launched Activity -->

>     <activity android:name=".MainActivity">
>         <intent-filter>
>             <action android:name="android.intent.action.MAIN" />
> 
>             <category android:name="android.intent.category.LAUNCHER" />
>         </intent-filter>
> 
>     </activity>
>     <activity
> 
>         android:name=".AddToBlocklistActivity"
> 
>         android:label="@string/app_name"
>         />
> 
> 
> 
> 
> </manifest>
> 

这里是Java代码

> 
> 
> 
>    package com.example.devnagi.callblocke.callblocker;
> 
> import java.util.List;
> 
> import android.app.AlertDialog; import android.content.Context; import
> android.content.DialogInterface; import android.content.Intent; import
> android.os.Bundle; import android.support.v7.app.ActionBarActivity;
> import android.view.LayoutInflater; import android.view.View; import
> android.view.View.OnClickListener; import android.view.ViewGroup;
> import android.widget.AdapterView; import
> android.widget.AdapterView.OnItemLongClickListener; import
> android.widget.ArrayAdapter; import android.widget.Button; import
> android.widget.ListView; import android.widget.TextView;
> 
> import com.example.devnagi.callblocke.R;
> 
> public class MainActivity extends ActionBarActivity implements
> OnClickListener, OnItemLongClickListener 
> 
>   // Declaration all on screen components of the Main screen  private
> Button add_blacklist_btn;     public ListView listview;       // Object of
> BlacklistDAO to query to database     private BlacklistDAO blackListDao;
>       // It holds the list of Blacklist objects fetched from Database
>   public static List<Blacklist> blockList;
>           // This holds the value of the row number, which user has selected for further action   private int selectedRecordPosition = -1;
> 
>   @Override   protected void onCreate(Bundle savedInstanceState) 
>       super.onCreate(savedInstanceState);
>       setContentView(R.layout.activity_main);
> 
>       // Initialization of the button of the Main screen
>       add_blacklist_btn = (Button) findViewById(R.id.add_blacklist_btn);
> 
>       // Attachment of onClickListner for it
>       add_blacklist_btn.setOnClickListener(this);
>               // Initialization of the listview of the Main screen to display black listed phone numbers      listview = (ListView)
> findViewById(R.id.listview);
>               // Set the header of the ListView       final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        final View
> rowView = inflater.inflate(R.layout.list_item, listview, false);
>       listview.addHeaderView(rowView);
>               // Attach OnItemLongClickListener to track user action and perform accordingly      listview.setOnItemLongClickListener(this);     
>   private void populateNoRecordMsg()  
> 
>       // If, no record found in the database, appropriate message needs to
> be displayed.         if(blockList.size() == 0)                  final TextView tv =
> new TextView(this);           tv.setPadding(5, 5, 5, 5);
>           tv.setTextSize(15);             tv.setText("No Record Found !!");
>           listview.addFooterView(tv);            
> 
>   @Override   public void onClick(View v)        // Render
> AddToBlocklistActivity screen once click on "Add" Button      if (v ==
> add_blacklist_btn)           startActivity(new Intent(this,
> AddToBlocklistActivity.class));                 @Override   public boolean
> onItemLongClick(AdapterView<?> parent, View view, int position, long
> id)          // If the pressed row is not a header, update
> selectedRecordPosition and        // show dialog for further selection        if
> (position > 0)           selectedRecordPosition = position - 1;
>           showDialog();              return true;           @Override   protected void
> onResume()       super.onResume();
>               // Initialize the DAO object        blackListDao = new BlacklistDAO(this);
>               // Fetch the list of Black listed numbers from Database using DAO object        blockList = blackListDao.getAllBlacklist();
>               // Remove the footer view       if(listview.getChildCount() > 1)            listview.removeFooterView(listview.getChildAt(listview.getChildCount()
> - 1));
>               //Now, link the  CustomArrayAdapter with the ListView       listview.setAdapter(new CustomArrayAdapter(this, R.layout.list_item,
> blockList));
>               // If, no record found in the database, appropriate message needs to be displayed.      populateNoRecordMsg();         private void
> showDialog()         // Before deletion of the long pressed record, need
> to confirm with the user. So, build the AlartBox first        final
> AlertDialog.Builder alertDialogBuilder = new
> AlertDialog.Builder(this);
>               // Set the appropriate message into it.         alertDialogBuilder.setMessage("Are you Really want to delete the
> selected record ?");
>               // Add a positive button and it's action. In our case action would be deletion of the data
>       alertDialogBuilder.setPositiveButton("Delete",
>               new DialogInterface.OnClickListener() 
>                   @Override
>                   public void onClick(DialogInterface arg0, int arg1) 
>                       try 
>                           
>                           blackListDao.delete(blockList.get(selectedRecordPosition));
>                           
>                           // Removing the same from the List to remove from display as well
>                           blockList.remove(selectedRecordPosition);
>                           listview.invalidateViews();
>                           
>                           // Reset the value of selectedRecordPosition
>                           selectedRecordPosition = -1;
>                           populateNoRecordMsg();
>                        catch (Exception e) 
>                           e.printStackTrace();
>                       
>                   
>               );
>               // Add a negative button and it's action. In our case, just hide the dialog box         alertDialogBuilder.setNegativeButton("Cancel",
>               new DialogInterface.OnClickListener() 
> 
>                   @Override
>                   public void onClick(DialogInterface dialog, int which) 
>                   
>               );
> 
>       // Now, create the Dialog and show it.      final AlertDialog
> alertDialog = alertDialogBuilder.create();        alertDialog.show();        
>   public class CustomArrayAdapter extends ArrayAdapter<String> 
> 
>       private LayoutInflater inflater;
>               // This would hold the database objects i.e. Blacklist      private List<Blacklist> records;
>               @SuppressWarnings("unchecked")      public CustomArrayAdapter(Context context, int resource,
> @SuppressWarnings("rawtypes") List objects)              super(context,
> resource, objects);
>                       this.records = objects;             inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);      
>               @Override       public View getView(int position, View convertView, ViewGroup parent) 
>                       //Reuse the view to make the scroll effect smooth           if(convertView == null)
>               convertView = inflater.inflate(R.layout.list_item, parent, false);
>                       // Fetch phone number from the database object          final Blacklist phoneNumber =  records.get(position);
>                       // Set to screen component to display results           ((TextView)convertView.findViewById(R.id.serial_tv)).setText("" +
> (position +1));
>           ((TextView)convertView.findViewById(R.id.phone_number_tv)).setText(phoneNumber.phoneNumber);
>           return convertView;                 

此屏幕截图显示了我在尝试运行应用程序时遇到的错误。它说'无法识别启动活动:未找到默认活动。启动活动时出错。 [1]:http://i.stack.imgur.com/vr1Jc.png

感谢您的帮助,感谢您的帮助。

【问题讨论】:

【参考方案1】:

如果您在升级 IDEA、升级 Android Studio 版本或生成新 APK 后发现该错误,您可能需要刷新和/或重新启动 IDE 的缓存。

File -> Invalidate Caches / Restart

【讨论】:

以上是关于无法识别启动活动,未找到默认活动启动活动时出错的主要内容,如果未能解决你的问题,请参考以下文章

启动应用程序时出错:未找到默认活动 - 两次中有一次

如何修复“运行‘应用程序’时出错:未找到默认活动”

当我有意启动它时,为啥android无法识别第二个活动?

运行应用小部件 - 无法识别启动活动

无法启动活动 ComponentInfo 二进制 XML 文件第 13 行:膨胀类 com.google.android.material.appbar.MaterialToolbar 时出错

无法从服务启动活动