i created an activity that holds all my activities in a list and declared them in the android manifest. But i keep getting an error "class exception not found". don't know what to do. here is the code and the android manifest.
package com.activityexample.cookbook;
import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class ExtendsListActivity extends ListActivity implements OnItemClickListener{
static final String[] Possible_Choices = new String[]{
"Open Website Example",
"Open Contacts",
"Open Dialer",
"Search Google Example",
"Start Voice Command"
};
final String searchTerms="supeman";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Possible_Choices));
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
getListView().setTextFilterEnabled(true);
getListView().setOnItemClickListener(this);
//getListView().setOnItemClickListener(new OnItemClickListener() {
// });
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
switch (arg2){
case 0:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com/")));
break;
case 1:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("content://contacts/people/")));
break;
case 2:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("tel://08160212611/")));
break;
case 3:
Intent i = new Intent(Intent.ACTION_WEB_SEARCH);
i.putExtra(SearchManager.QUERY, searchTerms);
startActivity(i);
break;
case 4:
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND));
break;
default: break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.activityexample.cookbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:maxSdkVersion="19" android:name="android.permission.READ_CONTACTS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".TheMenu"
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=".ActivityEx"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.activityexample.cookbook.ActivityEx" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".ExtendsListActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
Without seeing the specific error, it looks like this is not the error that you expect. It looks like Android is trying to launch your "MAIN" activity TheMenu, but you have not created that activity. If you don't have it, don't declare it. And then you should probably modify the manifest so that ExtendsListActivity is the MAIN:
<activity
android:name=".ExtendsListActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
If you do not declare activity in Manifest you will get the next error:
unable to find [Activity name]. Have you declared the Activity in your
Android Manifest
java.lang.ClassNotFoundException will usually occur when you are missing jar file, or declared the wrong package name for your custom view in XML file, like this guy.
Related
I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<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>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>
I have created 2 activities.When i call second activity from first via intent then onCreate method of second activity does not called.Although first activity's onCreate method is called normally as it should be.
Below is the code for first activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
int counter;
Button add, sub;
TextView tView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
tView = (TextView) findViewById(R.id.textView1);
// Intent in = new Intent(AC);
add.setOnClickListener(this);
sub.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bAdd:
tView.setText(++counter + "");
try {
Intent nextIntentView = new Intent(MainActivity.this, ShowValueActivity.class);
nextIntentView.putExtra("key", "counter");
startActivity(nextIntentView);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case R.id.bSub:
tView.setText(--counter + "");
break;
default:
break;
}
}
}
Code for second activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValue extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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.webesperto.webespertofirstapp.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=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
you have
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
instead of
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
Since your code reads
public class ShowValue extends Activity {
Though, why doesnt your application crash saying NoActivityFoundException ??
please have a look on manifest
change
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
to
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
yours manifest should be like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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.webesperto.webespertofirstapp.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=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
Change your Second Activity name in class file like this:
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValueActivity extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
It will work:)
Is there any way to use ADT's manifest merging feature (manifestmerger.enabled=true in project.properties) in Android Studio?
1. create sample project
2. add new module
3. Module Setting
4. Remove files in App Module
Move app/~~~/values/style.xml to common/~~~/values/style.xml
edit 1.
<!-- app/~~~/AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.susemi99.manifestmergerforandroidstudio" >
<application >
<activity
android:name="kr.susemi99.common.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
edit 2.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"> <!-- add this line -->
<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>
</application>
</manifest>
edit 3.
package kr.susemi99.common;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
Toast.makeText(getApplicationContext(), "test toast", Toast.LENGTH_LONG).show();
}
return super.onOptionsItemSelected(item);
}
}
See all http://susemi99.kr/2368
I'm very new in android and i am working on a app.
I meet problem in linking the 2nd page to the 3rd page while clicking the button. I had tried to solve the problem but it do not work. Below is my AndroidManifest.xml
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fyp"
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/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=".BelajarActivity"
android:label="#string/title_activity_main">
</activity>
<activity
android:name=".KnamaActivity"
android:label="#string/title_activity_main">
</activity>
</application>
</manifest>
below is BelajarActivity.java
package com.example.fyp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class BelajarActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.belajar);
Button bnama = (Button) findViewById(R.id.knama);
bnama.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent namaIntent = new Intent(BelajarActivity.this,KnamaActivity.class);
startActivity(namaIntent);
}
});
}
}
This
bnama.setOnClickListener(new Button.OnClickListener() { //this is wrong
...
});
should be
bnama.setOnClickListener(new View.OnClickListener() {
..
});
OnClickListener should be of type View
Just change this line
bnama.setOnClickListener(new View.OnClickListener() {
I want to create a splash screen that will then move to the login/register screen. My code looks like this:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AssaultTDActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.TimeOut();
}
public void TimeOut(){
long start = System.currentTimeMillis();
boolean continueloop = true;
long timenow;
while (continueloop = true){
timenow = System.currentTimeMillis();
if (timenow - start > 5000){
continueloop = false;
this.GoToRegister();
}
}
}
public void GoToRegister(){
Intent i = new Intent(AssaultTDActivity.this, register_activity.class);
startActivity(i);
finish();
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class register_activity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
}
}
and my manifest file is the following:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:screenOrientation="landscape"
android:label="#string/app_name"
android:name=".AssaultTDActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity class =".register_activity"
android:label="Log in"
android:screenOrientation="landscape"
android:name=".register_activity" >
</activity>
</application>
So am I doing something wrong here?
Also is there a command to "do events" while looping so you dot get stuck in a loop?
Hopefully this is the issue: looks like you may have had a find/replace mistake, this line in your manifest is wrong:
<uses-Activityk android:minActivitykVersion="8" />
Change it to:
<uses-sdk android:minSdkVersion="8" />
Because you added so many activities, it will most likely be fixed if you add:
<category android:name="android.intent.category.DEFAULT" />
So your main activity is the default activity and then the Android Launcher wont get tripped up.
<activity android:name=".MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Taken from: http://developer.android.com/reference/android/content/Intent.html
Activities will very often need to support the CATEGORY_DEFAULT so
that they can be found by Context.startActivity()