Android Error: Unable to find explicit activity class - java

As you can see in MainActivity.java, I am trying to show data, stored in SQLiteDatabse to List View but when data is already stored in database and else part run, my application get crashed at this point on going to showdata.class activity.
MainActivity.java
package com.example.crudwithlist;
public void onShow(View view) {
Database database=new Database(this);
SQLiteDatabase db= database.getReadableDatabase();
Cursor cursor=db.rawQuery("SELECT * FROM PRODUCT",new String[]{});
if(cursor.getCount()==0)
Toast.makeText(this, "No Saved Data", Toast.LENGTH_SHORT).show();
else{
Intent intent= new Intent(this,showdata.class);
startActivity(intent);
}
}
showdata.java
package com.example.crudwithlist;
public class showdata extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showdata);
//Calling showData method
showData();
}
public void showData(){
new Database(this);
new ArrayList<String>();
db=database.getReadableDatabase();
Cursor cursor=db.rawQuery("SELECT * FROM PRODUCT",new String[]{});
while(cursor.moveToNext()){
id=cursor.getInt(0);
name=cursor.getString(1);
des=cursor.getString(2);
price=cursor.getDouble(3);
list.add("id : "+id+"\t"+"Name : "+name+"\t"+"Description : "+des+"\t"+"Price : "+price+"\n");
}
new ArrayAdapter<>(this,R.layout.datastyle,list);
listView.setAdapter(adapter);
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crudwithlist">
<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/Theme.CRUDwithList">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Error at Line, in MainActivity.java
**
62> startActivity(intent);
**
Error Description
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.crudwithlist/com.example.crudwithlist.showdata}; have you declared this activity in your AndroidManifest.xml?
at com.example.crudwithlist.MainActivity.onShow(MainActivity.java:62)

Your problem is that the class is not included in the manifest file.
If you look, you'll notice that following code is in your manifest:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You will have to do pretty much the same for your showdata.java class.
Solution. Add this to your Android Manifest file:
<activity android:name=".showdata"/>

Related

Error: Activity class {com.example.thejourney/com.example.thejourney.WelcomeActivity} does not exist

I'm trying to test an Android app I'm working on, I can see the app on the emulator but I get an error whenever I try to install it on the phone.
I've already tried all the methods listed on other similar posts but the solutions don't seem to work on my situation.
A big part of me tells me the problem is there's repetition in the activity name as in Error: Activity class {**com.example.thejourney/**com.example.thejourney.WelcomeActivity} does not exist. instead of com.example.thejourney.WelcomeActivity. If that's the case, I don't know where it's coming from, I've checked.
Welcome Activity
public class WelcomeActivity extends Activity {
public static int SPLASH_TIME_OUT = 5000;
LinearLayout l1,l2;
ImageView logo;
Animation uptodown,downtoup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_welcome);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent mainIntent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(mainIntent);
finish();
}
}, SPLASH_TIME_OUT);
logo = (ImageView) findViewById(R.id.logo);
l1 = (LinearLayout) findViewById(R.id.l1);
l2 = (LinearLayout) findViewById(R.id.l2);
uptodown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
downtoup = AnimationUtils.loadAnimation(this,R.anim.downtoup);
l1.setAnimation(uptodown);
l2.setAnimation(downtoup);
}}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thejourney">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
/>
<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"
android:usesCleartextTraffic="true">
<activity
android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ProfileActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".AboutActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Your device might not work because developer mode and USB debugging might not be enabled. Try following the steps in https://developer.android.com/studio/run/device#setting-up.

Cannot Launch Activity but No Errors Appear[AlarmReminder]

I recently was studying making an AlarmReminder on youtube by this man's tutorial videos: DelaroyStudios.
Anyway... I followed his tutorial and made it work on a separate app. So next I modified it to the way I want my alarmreminder to be and tried to add it to my activity, however when I click the button routing to its activity launcher, it won't go off. By the way here's the repo: https://github.com/delaroy/AlarmReminder
I tried debugging but I can't see errors, so I really don't know where to start in fixing this part. But I suspect its on the dependencies on the gradle perhaps? or some other factor? Anyway please take a look at my code where I suspect the problem might be coming from.
Here's the manifests:
My Manifest
<application
android:name=".FireApp"
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.loginpack.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.loginpack.LoginActivity" />
<activity android:name=".MainActivity" />
<activity android:name="com.Welcome.Welcome" />
<activity android:name="com.Welcome.CalendarActivity" />
<activity android:name="com.Welcome.Video" />
<activity android:name=".Profile" />
<activity android:name="com.Welcome.Image">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.MainReminder">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.AddReminderActivity"
android:label="#string/title_activity_add_reminder"
android:parentActivityName="com.alarmreminder.MainReminder"
android:theme="#style/AppTheme">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.alarmreminder.MainReminder"
/>
</activity>
<activity android:name="com.Welcome.Info" />
<activity android:name=".Profile2" />
<activity android:name=".Profile3"/>
I checked the code and I suspect nothing except for some deprecated codes that were usually couldn't have affected the overall performance of the activity to the point that it can't even be opened and debugged. Please help me find a way to make this work. or perhaps if you know any method for me to debug activities without any errors showing. Oh and by the way this is what shows in the Verbose when I click on the activity.
Here's the code of the Activity mentioned:
public class MainReminder extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private FloatingActionButton mAddReminderButton;
private Toolbar mToolbar;
AlarmCursorAdapter mCursorAdapter;
AlarmReminderDbHelper alarmReminderDbHelper = new AlarmReminderDbHelper(this);
ListView reminderListView;
private static final int VEHICLE_LOADER = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainalarm);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setTitle(R.string.app_name);
reminderListView = findViewById(R.id.list);
View emptyView = findViewById(R.id.empty_view);
reminderListView.setEmptyView(emptyView);
mCursorAdapter = new AlarmCursorAdapter(this, null);
reminderListView.setAdapter(mCursorAdapter);
reminderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(MainReminder.this, AddReminderActivity.class);
Uri currentVehicleUri = ContentUris.withAppendedId(AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, id);
// Set the URI on the data field of the intent
intent.setData(currentVehicleUri);
startActivity(intent);
}
});
mAddReminderButton = findViewById(R.id.fab);
mAddReminderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AddReminderActivity.class);
startActivity(intent);
}
});
getLoaderManager().initLoader(VEHICLE_LOADER, null, this);
}
#Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
String[] projection = {
AlarmReminderContract.AlarmReminderEntry._ID,
AlarmReminderContract.AlarmReminderEntry.KEY_TITLE,
AlarmReminderContract.AlarmReminderEntry.KEY_DATE,
AlarmReminderContract.AlarmReminderEntry.KEY_TIME,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_NO,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_TYPE,
AlarmReminderContract.AlarmReminderEntry.KEY_ACTIVE
};
return new CursorLoader(this, // Parent activity context
AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, // Provider content URI to query
projection, // Columns to include in the resulting Cursor
null, // No selection clause
null, // No selection arguments
null); // Default sort order
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
mCursorAdapter.swapCursor(cursor);
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
mCursorAdapter.swapCursor(null);
}
}
PS: In the my manifest I didn't make it as the main launcher, since its only an activity after all.

Activity reopens when a NFC Tag is found

I'm developing an app that should detect NFC tags.
My problem is that my activity reopens every time the app scans a tag. It should just open when the app is closed. But when it is active, I just want the data from the tag.
Manifest:
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.corinna.nfc_testapp" >
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="14"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
Activity onCreate & handleIntent
rotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Fragment ReadOrWrite
fRead = (Fragment_Read) Fragment.instantiate(getApplicationContext(), Fragment_Read.class.getName(), null);
Fragment_ReadOrWrite fReadOrWrite = (Fragment_ReadOrWrite) Fragment.instantiate(getApplicationContext(), Fragment_ReadOrWrite.class.getName(), null);
fReadOrWrite.setFragment_Read(fRead);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.id_activity_main, fReadOrWrite);
fragmentTransaction.commit();
//NFC
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
String action = intent.getAction();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
String type = intent.getType();
if (MIME_TEXT_PLAIN.equals(type)) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefReaderTask ndefReader = new NdefReaderTask(fRead);
ndefReader.execute(tag);
} else {
System.out.println("Wrong mime type: " + type);
}
}
}
Just use launchMode="singleTop" in your main activity manifest.
This will ensure that if your activity is at the top of your task stack, it will not be recreated.
Be aware that onCreate is no longer called in this case, so if you want to read the content from intent, you need to override the onNewIntent Activity method.

Android service turns red

I want to add a service to my manifest but it gives a warning in.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aura_apps.tygo_asbroek.intentexample" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".TygoIntentService"
>
</service>
</application>
Here is the Java code:
package com.aura_apps.tygo_asbroek.intentexample;
public class TygoIntentService extends IntentService {
private static final String TAG = "com.bluelionapps.intentexample";
public TygoIntentService(String name) {
super("TygoIntentService");
}
#Override
protected void onHandleIntent(Intent intent) {
//This is what the service does
Toast toast = Toast.makeText(getApplicationContext(), "Service Lauched", Toast.LENGTH_SHORT);
toast.show();
}
}
Here you see my complete Manifest but .TygoIntentService says TygoIntentService.java doesn't have a default constructor of my app. If i run it, it's just working but I want to know if this can give any problems in the future and if it gives one what i need to do.
Remove String name parameter from the constructor:
public TygoIntentService() {
super("TygoIntentService");
}
If you do not use/need the name String there, just remove the constructor, and let the compiler add it behind scenes by default.

Change page via BroadcastReceiver does not work

I am trying to make a second page show up via a BroadcastReceiver, but the App keeps crashing and I don't know why.
This might be a problem of the correct context.
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.v("$$$$$", "In Method: ACTION_SCREEN_OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.v("$$$$$", "In Method: ACTION_SCREEN_ON");
changeActivity(context);
} else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Log.v("$$$$$", "In Method: USER_PRESENT");
}
}
public void changeActivity(Context context) {
Intent intent = new Intent(context, Second_Page.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
}
My Manifest. In there I declare the class that the log file states is missing:
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".CatchUnlockActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="second_page" >
</activity>
</application>
</manifest>
Found the solution:
The declaration of the classes is case-sensitive!
Changed every occurrence from "second_page" to "Second_Page" and now it works.

Categories

Resources