Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.colegiul.orar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".StartingPoint" android:label="#string/app_name" >
<intent-filter>
<action android:name="com.colegiul.orar.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ourClass"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Menu" android:label="#string/app_name" >
<intent-filter>
<action android:name="com.colegiul.orar.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Menu.java:
package com.colegiul.orar;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
String classes[] ={"StartingPoint", "Clasa a 9-a A", "Clasa a 9-a B"
, "Clasa a 9-a C", "Clasa a 9-a D", "Clasa a 9-a E", "Clasa a 9-a F"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
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) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese =classes[position];
try{
Class ourClass = Class.forName("com.colegiu.orar." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
StartingPoint.java
package com.colegiul.orar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class StartingPoint extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.starting_point, menu);
return true;
}
}
main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".StartingPoint" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/orar" />
</RelativeLayout>
My app is strarting with a splash screen which works perfectly, and opens a new menu, which contains a list with 7 examples and the first one "StartingPoint" should open a new activity, but it doesn't, and my head almost blew up trying to figure out why was that.. can anyone tell my please, why is doesn't work properly? Thanks.
O, PS:
Please be very patient and explain me detailed bacause I am a newbie.
Your onListItemClick has something like:
Class ourClass = Class.forName("com.colegiu.orar." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
and your manifest has a packaged name defined as: package="com.colegiul.orar".
Obviously won't work!
You should replace the above line by the following one
Class ourClass = Class.forName("com.colegiul.orar." + cheese);
EDIT:
After this, you have another problem instanciating your Intent because your cheese values are not declared as activities in manifest.
String classes[] ={"StartingPoint", "Clasa a 9-a A", "Clasa a 9-a B"
, "Clasa a 9-a C", "Clasa a 9-a D", "Clasa a 9-a E", "Clasa a 9-a F"};
Your classes array only contains one Activity name declared in app's manifest. The others are not. (Actually you can't declare activities with spaces - they are not valid!!) Thus you should be faced with a message in the stacktrace like "Are you declared this Activity in the Manifest" or an exception could be thrown (ClassNoFoundException).
Two points:
1) put .class after ourClass, while calling ourClass activity. Like this
Intent ourIntent = new Intent(Menu.this, ourClass.class);
startActivity(ourIntent);
2) Your second activity is not registered in manifest.xml.Register it like this
<activity
android:name=".ourClass"
android:label="#string/app_name" >
</activity>
I think the problem is that you not declare your second activity in your Manifest.
For each Activity, you need to declare it in your Manifest.xml as below:
<activity
android:name="com.colegiul.national.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="com.colegiul.national.SecondActivity"
android:label="#string/app_name" >
// You declared the Intent-filter as an Activity. This is wrong. An Intent-filter
// is to inform the system of the capability of the component, not the name of your
// Activity or the package. It is to the say what is your Activity will do.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.colegiul.national.ThirdActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And also, as #Vikram said, you need to call your Intent like this:
Intent myIntent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(myIntent);
You need to set the Context at first parameter and the Class at the second. See this documentation for more details: Build Intent Documentation
EDIT:
In your case, try to create your Intent as below:
String packClass = "com.colegiul.orar." + cheese;
Intent ourIntent = new Intent(Menu.this, Class.forName(packClass));
startActivity(ourIntent);
Related
I am new to android development, and I'm trying to add a splash screen in my app.
I found this tutorial:
I have added the files as mentioned in the tutorial but it doesn't seems to work, there is an error in my Splashscreen.java file
It gives me the error cannot resolve symbol androidmkab
Thanks for helping in advance.
Splashscreen.java
package com.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageView;
import com.androidmkab.randomsplash.MainActivity;
import java.util.Random;
public class Splashscreen extends Activity {
Thread splashTread;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
imageView = (ImageView)findViewById(R.id.imageView2);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
int[] ids = new int[]{R.drawable.s_img,R.drawable.s_image_black, R.drawable.s_image_black2};
Random randomGenerator = new Random();
int r= randomGenerator.nextInt(ids.length);
this.imageView.setImageDrawable(getResources().getDrawable(ids[r]));
splashTread = new Thread() {
#Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 3500) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(Splashscreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
Splashscreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
Splashscreen.this.finish();
}
}
};
splashTread.start();
}
}
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:layout_gravity="center"
android:id="#+id/lin_lay"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/splash"
android:background="#drawable/logo" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapplication">
<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=".Splashscreen"
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=".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.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
import com.androidmkab.randomsplash.MainActivity; remove this line from the top. Its not your package... instead make it import com.myapplication.MainActivity
the problem seems to be that you are trying to call a package which does not exist in your project. androidmkab.randomsplash.MainActivity should be replaced with your project package. such as com.myApplication.MainActivity
Delete the line com.androidmkab.randomsplash.MainActivity; and write com.myapplication.MainActivity;
Friends,
I Have created an android file in eclipse and Exported as an android file. When i install it i got two android files. I have two java files in the app. one is second.java and the other is first.java.
When i install the app in blue stacks , it installed two files . One is first and other is second.
I have a button in my first.java which goes to the second.java file. How can i solve it by installing only one app in app tray...???
Here is my code
first.java
package com.zacter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class first extends Activity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void addListenerOnButton(){
final Context context=this;
button=(Button) findViewById(R.id.continuebutton);
button.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Intent intent = new Intent(context,second.class);
startActivity(intent);
}
});
}
}
Second.java
package com.zacter;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class second extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_boostram);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.boostram, menu);
return true;
}
}
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zacter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.zacter.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.zacter.SettingsActivity"
android:label="#string/title_activity_settings"
android:parentActivityName="android.app.LauncherActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.LauncherActivity" />
</activity>
<activity
android:name="com.zacter.Boostram"
android:label="#string/title_activity_boostram" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Replace 'LAUNCHER' with 'DEFAULT'
See here for further explaination
In your manifest files, you are having more than one activities with the intent filter category as launcher.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The intent category means you are going to have two launcher icons, or two launch points for your application.
You can read more about it here
http://developer.android.com/guide/topics/manifest/category-element.html
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zacter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.zacter.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.zacter.SettingsActivity"
android:label="#string/title_activity_settings"
android:parentActivityName="android.app.LauncherActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.LauncherActivity" />
</activity>
<activity
android:name="com.zacter.Boostram"
android:label="#string/title_activity_boostram" >
</activity>
</application>
</manifest>
just Because of these lines.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
keep this intent filter for only one activity which you want to launch at starting. if you keep category launcher for any other activities it will creates multiple launcher icons in applications. for more details check this link here
Keep this tag in only first activity remove from Boostram activity tag
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<category android:name="android.intent.category.LAUNCHER" /> will create launcher activity, so if you have multiple LAUNCHER category in AndroidManifest.xml file, multiple launcher activity will generate.
Modify your AndroidManifest.xml like below.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".first"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".second"
android:label="#string/title_activity_main" >
</activity>
</application>
I'm trying to play an video on my android app, but when I click on the activity through my menu list, the app stays on the list and doesn't play the video.
The code is below
my menu
package com.example.taekwondobuddy.util;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Kicks extends ListActivity {
String classes[] = {"FrontKick","RoundhouseKick","AxeKick"} ;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Kicks.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
Intent ourIntent = new Intent(Kicks.this, ourclass);
startActivity(ourIntent);
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
the video I'm trying to play
package com.example.taekwondobuddy.util;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class RoundhouseKick extends Activity {
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.roundhousekick);
mVideoView = (VideoView) findViewById(R.id.roundhousekick);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.roundhousekick));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
the xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="#+id/roundhousekick"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taekwondobuddy.util"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.taekwondobuddy.util.Menu"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Tools"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Techniques"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Kicks"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Counter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Time"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Accelermeter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.FrontKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.RoundhouseKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.AxeKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
I think it something wrong with the manifest but I can't really see what's wrong, any ideas? Plus the video are in mp4 so they're are in the right format for android
I think, you just missed one little thing: a dot (.)
See at your code here:
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
don't you think it should be like this:
Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
Try to use:
mVideoView.start();
I know I already asked this, but I didn't get a sufficient answer. Im trying to start an activity, but the emulator stays on the first activity. Ive tried all ways to do it but it never works. The youtube videos show that it should work but it never does. Is there something missing or is there anything wrong with the following code?
//First Activity:
package com.mtprogramming.magicsquaresgame;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
public class Opening extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opening);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
Intent open = new Intent("com.mtprogramming.magicsquaresgame.MENU");
startActivity(open);
}
}
};
timer.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.opening, menu);
return true;
}
}
//Second Activity:
package com.mtprogramming.magicsquaresgame;
import android.app.Activity;
import android.os.Bundle;
//Created by suprav on 7/11/13.
public class Menu extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
}
}
//Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mtprogramming.magicsquaresgame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.mtprogramming.magicsquaresgame.Opening"
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="com.mtprogramming.magicsquaresgame.Menu"
android:label="#string/title_activity_menu"
android:parentActivityName="Opening" >
<intent-filter>
<action android:name="com.mtprogramming.magicsquaresgame.MENU"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="Opening" />
</activity>
</application>
</manifest>
Try this:
Intent open = new Intent(Opening.this, Menu.class);
startActivity(open);
I think i found the issue, seems like metadata property is not being properly used, hences activity its not being started, this is the proper way to use the property:
<activity android:name=".TestActivity" >
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".TestParentActivity">
</meta-data>
</activity>
So, seems like you are missing a dot in "android:value="Opening"
Regards!
Im trying to get my menu inflater to link to my layout file, but when app launches and I hit menu, then select menu option it crashes program. It says it cannot find activity to launch:
error in eclipse LogCat:
01-01 10:24:38.799: E/AndroidRuntime(30359): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.menu/com.menu.AboutUs}: java.lang.ClassNotFoundException: com.menu.AboutUs in loader dalvik.system.PathClassLoader[/data/app/com.menu-1.apk]
Main Code:
package menu;
import com.menu.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
public class testActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.new_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.aboutUs:
Intent i = new Intent("menu.ABOUT");
startActivity(i);
break;
case R.id.settings:
break;
}
return false;
}
Manifest code:
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name="menu.testActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutUs"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog">
<intent-filter >
<action android:name="menu.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
about.xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:text="Why dosent this work??????????????????????? "
android:title="About Us"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
I would gratefully appreciate help... thank you
If you want to launch say Activity B from Activity A, you should make sure that you have declared Activity B in your manifest file.Then in your onOptionsItemSelected(), you can say,
Intent i = new Intent(this,B.class);
startActivity(i);
If you want to start activity using Action parameter for intent you can use the following in the Activity tag in the mafifest.
This is considering activity B is in the application package directly
<activity android:name=".B">
<intent-filter>
<action android:name="menu.ABOUT" />
</intent-filter>
</activity>
You got Class not found exception for com.menu.AboutUs - pretty straightforward