0

I just made a minimal application and i have ran into a problem solving it. i get this error after running it. " Could not identify launch activity: Default Activity not found Error while Launching activity "

I tried editing the Manifest file and added the main activity package like this : "com.example.loanapplication.MainActivity " and edited the configuration and 'specified the activity' but then after running it, the same error appeared.

MainActivity

public class MainActivity extends AppCompatActivity {

    private ListView listViewLoans;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try{
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            List<Loans> loans = new HttpRequestLoansList().execute().get();
            listViewLoans = (ListView) findViewById(R.id.listViewLoans);
            listViewLoans.setAdapter( new LoanListAdapter(loans, getApplicationContext()));
        }
        catch (Exception e){
            AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
            builder.setMessage(e.getMessage());
            builder.create().show();
        }

    }

    private  class HttpRequestLoansList extends AsyncTask<Void, Void, List<Loans>>{

        @Override
        protected List<Loans> doInBackground(Void... params) {
            LoanModel loanModel = new LoanModel();
            return  loanModel.all();
        }

        @Override
        protected void onPostExecute(List<Loans> loans) {
            super.onPostExecute(loans);
        }
    }

Manifest File

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


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.example.loanapplication.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>




    </manifest>

activity_main xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/buttonAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Loan" />

    <ListView
        android:id="@+id/listViewLoans"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

error inlclude the following: Could not identify launch activity: Default Activity not found Error while Launching activity

expectations:

  • first guess change into – noname Aug 13 '19 at 14:11
  • @noname there is no reason to do this as the 2 declarations are essentially identical. – David Wasser Aug 13 '19 at 14:57
  • Your manifest and code look OK. This sounds like an Android Studio problem that it (for some reason) can't find the `Activity` to launch. – David Wasser Aug 13 '19 at 14:59
  • @DavidWasser not sure what do you mean. I think android get confused when is looking for MainActivity in com.example.loanapplication.com.example.loanapplication. package (yes, it is looking in nested packages) – noname Aug 13 '19 at 14:59
  • but also you can check this post https://stackoverflow.com/questions/33855518/could-not-identify-launch-activity-default-activity-not-found/33855565 – noname Aug 13 '19 at 15:15
  • Possible duplicate of [Could not identify launch Activity: Default Activity not found](https://stackoverflow.com/questions/33855518/could-not-identify-launch-activity-default-activity-not-found) – noname Aug 13 '19 at 15:15
  • check the project structure if the MainActivity class is under the right package like com.example.loanapplication/MainActivity – Walid Aug 13 '19 at 15:58
  • Have you tried restarting Android Studio? Or maybe just create a new project and try again. I'm convinced that Android Studio is just confused. – David Wasser Aug 13 '19 at 17:02
  • I have configured my Manifest file to look like : ``` ... ``` but not working. Toast error "The activity MainActivity is not declared in the AndroidManifest.xml" – Nehemiah Limo Aug 13 '19 at 18:47
  • @NehemiahLimo, do you have MainActivity in a subfolder? If your subfolder is named "somefolder" then you would have ".somefolder.MainActivity" in the manifest. – brandonx Aug 13 '19 at 20:34

1 Answers1

-1

Please go to Build > clean project and then build that again

noname
  • 565
  • 6
  • 23
  • Guys you are right. I had that issue before and suggested solution was one of thing which I have done, but that does not fix the issue. I think for me that happen when I switch the project and then I had to clean the project and build it. Because I think a cache issue and android get confused when I change project. – noname Aug 13 '19 at 20:22