Force stop when run app in moblie - android

I try to work with list view and on click open another activity but when I run the app on mobile it force stop. Below is my code for Main activity
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemClickListener {
String TopicList[]={"jan","Feb"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView=(ListView) findViewById(R.id.topic);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position==0){
Intent myInternt= new Intent(view.getContext(),Vlookup.class);
startActivityForResult(myInternt,0);
}
if (position==1){
Intent myInternt= new Intent(view.getContext(),Hlookup.class);
startActivityForResult(myInternt,1);
}
}
}
Blockquote
Below my Maindest.xml file
`enter code here
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Vlookup" />
<activity android:name=".Hlookup"></activity>
</application>

Replace this line from the code:-
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
by:-
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);
you are not adding list to adapter therefore it crashes,
And also check the manifest that the activity is added to it.

Make sure you have defined MainActivity, Vlookup and Hlookup in your manifest
<activity android:name=".MainActivity"/>
<activity android:name=".Vlookup"/>
<activity android:name=".Hlookup"/>
and replace
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
by
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList);

Related

android.content.ActivityNotFoundException: Unable to find explicit activity class

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>

Error : MainActivity is not an enclosing class

I create a personnal component view and when we click on this, an other activity starts. There is my manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.freshkamekentrainement.skrt">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".Splash"
android:theme="#style/Splash"
android:screenOrientation="portrait"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
<activity android:name=".niveaux.LilUziVert_GrowUp"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
</application></manifest>
there is my intent
public class Niveauview extends RelativeLayout {
Intent intentNiveau;
//Code
#Override
public void onFinishInflate() {
super.onFinishInflate();
setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
intentNiveau = new Intent(MainActivity.this,LilUziVert_GrowUp.class);
startActivity(intentNiveau);
}
});
}}
I get error:
MainActity is not an enclosing class
Notice that NiveauView and MainActivity isn't in the same package (but they are public). Where does the problem come from? When i try new Intent(this,LilUziVert_GrowUp.class); i have an error too.
You can only access Foo.this if you're in a inner class of Foo. Otherwise you need to be passed in an instance of Foo instead. In the case of a View, every view has an instance of a Context you can get by calling getContext(). So you need to call intentNiveau = new Intent(getContext(),LilUziVert_GrowUp.class);

ListFragment does not show title bar in Android Studio

Why title bar not show it in the ListFragment?
I did not set fullscreen or other.Please help me
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".CrimeListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".CrimePagerActivity"
android:label="#string/app_name">
</activity>
</application>
CrimeListFragment.java
public class CrimeListFragment extends ListFragment {
private ArrayList<Crime> mCrimes;
private static final String TAG = "CrimeListFragment";
private Crime c;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
getActivity().setTitle(R.string.crimes_title);
mCrimes = CrimeLab.get(getActivity()).getCrimes();
CrimeAdapter adapter = new CrimeAdapter(mCrimes);
setListAdapter(adapter);
...
}
}
Check, if there isn't for example "AppTheme.NoActionBar" as your app theme at Design, in your fragment xml file.
change the theme of your activity in manifest.
android:theme=""

I am not able to switch to another Activity from a ListView activity

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);

Cannot start activity using explicit intent

I have Starter ListActivity which starts two others: Multitouch and Accelerometer.
When the first one is touched in ListActivity it is launched very well.
The second one, however, isn`t laucnched.
Logcat reports:
06-09 22:42:55.293 12227-12227/com.mainpackage.api E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.mainpackage.api/com.mainpackage.api.Accelerometer};
have you declared this activity in your AndroidManifest.xml?
I have read related questions but they didn't help me out.
Starter activity:
public class Starter extends ListActivity {
private String[] tests = { "MultiTouch", "Accelerometer" };
#Override
public void onCreate(Bundle saved) {
super.onCreate(saved);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tests);
this.setListAdapter(adapter);
}
#Override
public void onListItemClick(ListView list, View view, int position, long id) {
super.onListItemClick(list,view,position,id);
String test = tests[position];
try {
Class clazz = Class.forName("com.mainpackage.api."+test);
Intent i = new Intent(this,clazz);
startActivity(i);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mainpackage.api">
<application android:allowBackup="true" android:label="#string/app_name"
android:icon="#mipmap/ic_launcher" android:theme="#style/AppTheme">
<activity
android:name=".Starter"
android:label="#string/app_name"
>
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".MultiTouch"
android:label="MultiTouch" />
<activtiy
android:name=".Accelerometer"
android:label="Accelerometer" />
</application>
</manifest>
MultiTouch and Accelerometer have no bugs. I have tried them separate.
Any ideas ?
First, do not use Class.forName(). Either use if or a Class[] and just reference the Accelerometer.class and MultiTouch.class objects.
Second, your manifest has:
<activtiy
android:name=".Accelerometer"
android:label="Accelerometer" />
which has the element name spelled incorrectly. Try:
<activity
android:name=".Accelerometer"
android:label="Accelerometer" />

Categories

Resources