"No Activity found" error - java

This is my main page code:
package com.example.splasher;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
public static String text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide statusbar of Android
// could also be done later
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
EditText field= (EditText) findViewById (R.id.editText1);
field.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus) ((EditText)v).selectAll();
}
});
text=field.getText().toString();
try{
startActivity(new Intent("com.example.splasher.View"));
}
catch(ActivityNotFoundException e){
}
}
});
}
}
This is the code of my called activity:
package com.example.splasher;
import android.os.Bundle;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
public class View extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide statusbar of Android
// could also be done later
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.view);
// TextView textview=(TextView) findViewById (R.id.textView1);
// textview.setText(MainActivity.text);
}}
And this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.splasher"
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=".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=".View"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.splasher.View" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I can't work out why I get this error. Any ideas? Names are all the same and with same upper, lower case letters. They are all described in manifest as well.

In your manifest, type the activity action in caps.
< action android:name="COM.EXAMPLE.SPLASHER.VIEW" / >
this is done for all activities except for the main activity

There is MainActivity.this.startActivity(new Intent(MainActivity.this, Views.class)); Views class with 's' !

there is no need of the intent filter which you have applied in the View activity..Just keep one intent filter in your MainActivity
Replace the start activity line code with following:
startActivity(new Intent(MainActivity.this,View.class));

Try to replace your startActivity call by MainActivity.this.startActivity in your MainActivity.
I think there is a scope trouble.

Related

Access the volume button through my android app

I am developing an android app which should be able to identify when someone press the hardware volume up button of the phone , and give a notification saying "volume up button has pressed".
This is my BroadcastReceiver class.
package com.example.volumebut;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.widget.Toast;
public class HardwareButtonReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
KeyEvent e = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if(e.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
Toast.makeText(context, "volume up button pressed." ,Toast.LENGTH_LONG).show();
}
}
}
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.volumebut"
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.volumebut.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>
<receiver android:name=".HardwareButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
</application>
</manifest>
Since I am new to android development I have no idea how to implement MainActivity.java file.
This is the MainActivity.java file I have wrote so far. But it gives an error saying "The method registerMediaButtonEventReceiver(HardwareButtonReceiver) is undefined for the type MainActivity"
package com.example.volumebut;
import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.Menu;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
HardwareButtonReceiver receiver = new HardwareButtonReceiver();
registerMediaButtonEventReceiver(receiver);
}
}
If you guys can help me to solve my problem I appreciate It much.
http://developer.android.com/reference/android/view/KeyEvent.html
go through above link you will get different key events
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
//
}
else if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
}
return super.onKeyDown(keyCode, event);
}
You must add method registerMediaButtonEventReceiver to your activity class.
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml_of_your_activity);
HardwareButtonReceiver receiver = new HardwareButtonReceiver();
registerMediaButtonEventReceiver(receiver);
}
private void registerMediaButtonEventReceiver(HardwareButtonReceiver receiver) {
}
}
And then implement it of course.

Unfortunately, app has stopped

Unfortunately, app has stopped. The purpose of the app is to display a web page when it is launched. I have researched this problem, and tried changing code in the manifest file. I have been unsuccessful at eliminating this message.
MainActivity.java
package com.example.testb1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
}
testb1 Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testb1"
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.example.testb1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.getmobilepages" />
</intent-filter>
</activity>
</application>
</manifest>
Edit: I tried running your code and was completely wrong. You are just missing the line:
super.onCreate(savedInstanceState);
At the start of your oncreate method. Add that in and it should compile just fine.
Make sure to post your logcat in the future, the error is identified clearly there.
You have not called super you will get SuperNotCalled Exception. You need to set you layout. Better to start another activity on button click.
Add internet permission in manifest
<uses-permission android:name="android.permission.INTERNET"/>
MainActivty
public class MainActivity extends Activity {
Button b;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// call super
setContentView(R.layout.activity_main);
// set your layout
b = (Button) findViewById(R.id.button1);
//get button id
b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// do something
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
});
}
}

OnClick doesn't appear to be getting called

I am trying to open a web browser window onclick of a button.
My click event doesn't appear to be getting called. LogCat shows no errors or any evidence of it being called. I have a feeling this is due to me having 2 methods named 'onClick', but removing the second method causes an error. I can fix this error by making MainActivity abstract, but that crashes the app.
I feel this is a simple fix, but after pouring over documentation and several tutorials I cannot find the answer.
Code is below, followed by my manifest. Thanks in advance.
package com.spotsofmagic.spotsofmagic;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
private static final String TAG = "Activity...";
private NfcAdapter mAdapter;
private TextView mTextView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
// grab our NFC Adapter
mAdapter = NfcAdapter.getDefaultAdapter(this);
// TextView that we'll use to output messages to screen
mTextView = (TextView)findViewById(R.id.text_view);
//displayMessage("Loading payload...");
}
private void displayMessage(String message) {
mTextView.setText(message);
}
public void onClick(View v) {
// TODO Auto-generated method stub
// do something when the button is clicked
displayMessage("Loading broswer");
Uri uriUrl = Uri.parse("http://www.***.com/");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
if(v.getId() == R.id.btnVisitWebsite) {
}
}
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
And the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spotsofmagic.spotsofmagic"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<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=".CardActivity"
android:label="#string/app_name" >
<!-- Handle a collectable card NDEF record -->
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<data android:mimeType="application/vnd.spotsofmagic.spotsofmagic"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
You have an OnClickListener but you didn't attach it to any button. Try
((Button) findViewById(R.id.your_button_id)).setOnClickListener(this);
EDIT: The other problem is, that you implemented DialogInterface.OnClickListener instead of View.OnClickListener in your Activity.
Remove the imports
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
And add
import android.view.View.OnClickListener;
You can also remove
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
after this.
Because you didn't associate the click event.
If you are binding it to button (or) something, you need to do bind it for 'this'
Example:
button.setOnClickListener(this);
To avoid confusion, you could also do it using the XML if you are not creating the view programatically. You can do something like this.
<Button android:width="20dp" android:height="20dp" android:onClick="openBrowser" />
and provide the method in your program as
public void openBrowser(View v)
{
/* do your stuff here */
}

error in xml parsing

i built a code that switch from one activity to another.
when run this code it prints following errors.
Error in an XML file: aborting build.
and
Installation error: INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID
here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wishme.code"
android:versionCode="1"
android:versionName="1.0" android:sharedUserId="#string/app_name">
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".WishMeActivity"
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=".Activity2"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
here is activity 1
package wishme.code;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts.Intents;
import android.widget.TextView;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class WishMeActivity extends Activity {
private EditText text;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text=(EditText) findViewById(R.id.editText1);
}
public void myClickhandler(View view)
{
switch(view.getId())
{
case R.id.button1:
RadioButton celsiusbutton=(RadioButton) findViewById(R.id.radio0);
RadioButton fahrenheit=(RadioButton) findViewById(R.id.radio2);
if(text.getText().length()==0)
{
Toast.makeText(this,"Enter a Valid Value",Toast.LENGTH_LONG).show();
return;
}
float input=Float.parseFloat(text.getText().toString());
if(celsiusbutton.isChecked())
{text.setText(String.valueOf(convertFahrenheitToCelsius(input)));
celsiusbutton.setChecked(false);
fahrenheit.setChecked(true);}
else
{
text.setText(String.valueOf(convertCelsiusToFahrenheit(input)));
fahrenheit.setChecked(false);
celsiusbutton.setChecked(true);
}
break;
case R.id.button_nxt:
Intent myintent=new Intent(view.getContext(),Activity2.class);
startActivityForResult(myintent, 0);
break;
}
}
private float convertFahrenheitToCelsius(float fahrenheit) {
return ((fahrenheit - 32) * 5 / 9);
}
// Converts to fahrenheit
private float convertCelsiusToFahrenheit(float celsius) {
return ((celsius * 9) / 5) + 32;
}
}
and finally this is activity 2
package wishme.code;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Activity2 extends Activity{
public void onCreate(Bundle savedInstancestate) {
super.onCreate(savedInstancestate);
setContentView(R.layout.main2);
Button previous=(Button) findViewById(R.id.button_prev);
}
public void prevclickhandler(View view)
{
Intent intent=new Intent();
setResult(RESULT_OK,intent);
finish();
}
}
please suggest me the solution.
I you just want to go from one activity to another, then you dont need to give the sharedUserID. Its used in cases where you have two different applications that are signed with same certificate and you want to share data between them or you want them to run in the same process.
If you remove it, it should solve your problem.
For information about sharedUserID: http://developer.android.com/guide/topics/manifest/manifest-element.html#uid
This may be due to your sharedUserId value being of a non-permitted value. It has to have the same format as the package structure (e.g. com.android).

Why can't I see my app in the avd app menu?

My app successfully installs on my AVD, I can confirm it was installed by seeing it in the app manager, but I can never access it because I can not see it in the app menu
In the console I always get the messages
[2011-12-27 10:39:28 - WhosurSensei] No Launcher activity found!
[2011-12-27 10:39:28 - WhosurSensei] The launch will only sync the
application package on the device!
my opening java page
package com.thepackage.WhosurSensei;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class WhosurSenseiActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Button1 = (Button) findViewById(R.id.firstpagebutton);
Button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(WhosurSenseiActivity.this, MainMenu.class));
}
});
}
#Override
protected void onPause() {
super.onPause();
}
}
my androidmanifest page
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/splash"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".WhosurSenseiActivity" >
<intent-filter >
<action android:name="com.thepackage.WhosurSensei.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".MainMenu" >
</activity>
</application>
</manifest>
Apparently the tutorial I was reading told me wrong and I needed this in the manifest:
<action android:name="android.intent.action.MAIN" />

Categories