I'm new to android and java programming and I'm getting ActivityNotFoundException in my app.
Here these are the only two times the activity is called:
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String selectedItem = (String) lvCheckLists.getItemAtPosition(position);
Intent i= new Intent("com.teamvdb.checklist.checkListActivity");
// Package name and activity
// Intent i= new Intent(MainActivity.this,SecondActivity.Class);
// Explicit intents
i.putExtra("selectedItem",selectedItem);
// Parameter 1 is the key
// Parameter 2 is your value
startActivity(i);
Intent openCheckListActivity = new ntent("com.teamvdb.checklist.checkListActivity");
startActivity(openCheckListActivity);
}
});
}
And here there is my Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.teamvdb.checklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/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=".checkListActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
I have spent the last 20 minutes trying to figure out what is wrong with it but I can't see the problem.
And yes the class is spelled correctly.
Explicitly start checkListActivity :
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String selectedItem = (String) lvCheckLists.getItemAtPosition(position);
Intent i= new Intent(MainActivity.this,checkListActivity.class);
i.putExtra("selectedItem",selectedItem);
startActivity(i);
});
intent-filter not required for checkListActivity so remove it and define as simple in AndroidManifest.xml :
<activity android:name=".checkListActivity"/>
Note : Remove unneccsary code which start checkListActivity again.
Related
I am trying to write a code that shows a list of apps and lets the user choose an app to delete. I wrote this code based on what i've seen online:
appListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri packageUri = Uri.parse(names.get(position));
Intent uninstallIntent =
new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);
}
});
However, for some reason I am getting this exception:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.UNINSTALL_PACKAGE dat=com.ivuu }
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
<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=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AppList"></activity>
</application>
I am pretty new to android and I spent the whole day on this... Please tell me what I am missing
Thanks
You do not have a scheme. Your Uri needs to be of the form package:..., where ... is the application ID/package name.
public class ListViewActivity extends AppCompatActivity
{
ListView lv;
String[] ListItems={"AutoCompleteTextViewActivity","CheckboxActivity","EditTextActivity","ListViewActivity","ProgressBarActivity","RadioButtonActivity","RatingBar2Activity","RatngBarActivity","SeekBarActivity","SpinnerActivity","SwitchActivity","TextViewActivity"};
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter ad=new ArrayAdapter(ListViewActivity.this,android.R.layout.simple_list_item_1,ListItems);
lv.setAdapter(ad);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent i = new Intent(ListViewActivity.this, ListItems[position].getClass());
startActivity(i);
}
});
}
}
i am current learning android studio.i made an app through which i can open my previously created apps by choosing them from a listview widget.it shows an error in the intent line.please tell me where i've have gone wrong.
MY MANIFEST FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.re1">
<application
android:allowBackup="true"
android:banner="#mipmap/ic_launcher_round"
android:icon="#mipmap/ic_launcher_round"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".TextViewActivity" />
<activity android:name=".EditTextActivity" />
<activity android:name=".RadioButtonActivity" />
<activity android:name=".CheckboxActivity" />
<activity android:name=".RatngBarActivity" />
<activity android:name=".RatingBar2Activity" />
<activity android:name=".ProgressBarActivity" />
<activity android:name=".SeekBarActivity" />
<activity android:name=".SwitchActivity" />
<activity android:name=".SpinnerActivity"/>
<activity android:name=".AutoCompleteTextViewActivity">
</activity>
<activity android:name=".ListViewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Add your activity name to your manifest file
<activity android:name=".ListViewActivity"></activity>
I have problem with my manifest. When I try to open the second Activity, I get the error android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION }
Find bellow my Manifest .xml contain
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxx.monapplication" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme" >
<activity android:name="com.xxxxx.monapplication.application.Accueil" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.xxxxx.monapplication.application.OwnerRegistration" >
<intent-filter>
<action android:name="android.intent.action.APPLICATION.OWNERREGISTRATION" />
<category android:name="android.intent.category.APPLICATION.DEFAULT" />
</intent-filter>
</activity>
An the part of my code to open second activity
btnMel.setOnClickListener( new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent("com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION");
startActivity(i);
}
}
Please help me to find the error.
You can call activity by its class name, then put your custom intent to setAction.
private String YOUR_ACTION = "com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION"
//uou can use this instead.
//Intent i = new Intent(this /* caller context */, OwnerRegistration.class);
Intent i = new Intent();
i.setAction(YOUR_ACTION);
startActivity(i);
try this code..
Intent myIntent = new Intent(YourActivity.this, OWNERREGISTRATION.class); startActivity(myIntent);
I have 3 activities in my application.
Start activity(with a timer of 5 sec after that Menu activity appears)
Menu activity
Main activity
The Menu Activity has a listview adapter.
I want to get the Main activity after clicking an item form the list but it is not switching to Main Activity after clicking.
Here is my Menifest file
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="THE APP"
android:theme="#style/AppTheme" >
<activity
android:name=".start"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter android:label="MAIN">
<action android:name="androphlie.myfirst.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="MENU" >
<intent-filter
android:label="MENU" >
<action android:name="androphlie.myfirst.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
The Menu.java is as follows
public class Menu extends ListActivity {
String classes[]={"MainActivity","example1","example2","example3","example4","example5"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String listitem=classes[position];
try {
Class ourClass = Class.forName("com.androfile.myfirst."+listitem);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch (ClassNotFoundException e){e.printStackTrace();
}
}}
I am new to android and not able to find out the problem in code
In your onListItemClick listener ,package name com.androfile.myfirst you entered is incorrect compared to manifest file com.androphlie.myfirst
Change
Class ourClass = Class.forName("com.androfile.myfirst."+listitem);
to
Class ourClass = Class.forName("com.androphlie.myfirst."+listitem);
07-18 04:48:22.465: E/AndroidRuntime(19105): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.liamwli.fa.yearbook/com.liamwli.fa.yearbook.Home}: java.lang.NullPointerException
That is the error I get.
I have defined the Home class in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liamwli.fa.yearbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And it only started doing this when I added the putExtras line in my main activity:
enter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
myname = name.getText().toString();
Intent i = new Intent("com.liamwli.fa.yearbook.HOME");
i.putExtra("myname", myname);
startActivity(i);
}
});
So, can anyone please explain what is happening?
use this:
Intent i = new Intent(context,otherActivity.class);
context of that activity from where you want to start activity.otherActivity is the name of activity which you want to start
Try this once
Intent i = new Intent(MainActivity.this,Home.class);
i.putExtra("myname", myname);
startActivity(i);
And I don't think this is required in Manifest
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
change like this
Intent i = new Intent(MainActivity.this, Home.class);
i.putExtra("myname", myname);
startActivity(i);
Try this...
Intent i = new Intent( YourActivityName.this , otherActivity.class);
Ok, I looked and it looked like I was setting a variable contents outside of the onCreate method. So that is why it wasn't working.