Opening Activity Crashes App - class

Hey guys I'm new to coding and iv'e recently been working on an app. I have set OnClickListener's to my buttons each leading to another class that I believe I stated in the Manifest. When I launch my app one of the buttons works but the other crashes the app and tells me that the class is not found please help. Here is some code:
public class CharPage extends ActionBarActivity {
private static Button button_next;
private static Button button_kk;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_char_page);
OnClickButtonListener();
}
public void OnClickButtonListener() {
{
button_kk= (Button) findViewById(R.id.buttonkk);
button_kk.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.jmac.mortalkombat.Kotal_Khan");
startActivity(intent);
}
}
);
}
button_next = (Button) findViewById(R.id.button);
button_next.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.jmac.mortalkombat.CharPage2");
startActivity(intent);
}
}
);
}
Then there is my Manifest:
<activity
android:name=".CharPage"
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=".CharPage2"
android:label="#string/title_activity_char_page2" >
<intent-filter>
<action android:name="com.example.jmac.mortalkombat.CharPage2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".CharPage3"
android:label="#string/title_activity_char_page3" >
<intent-filter>
<action android:name="com.example.jmac.mortalkombat.CharPage3" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Kotal_Khan"
android:label="#string/title_activity_kotal__khan" >
<intent-filter>
<action android:name="com.example.jmac.mortalkombat.Kotal_Khan" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
The StackTrace:
26010-26010/com.example.jmac.mortalkombat E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jmac.mortalkombat, PID: 26010
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.jmac.mortalkombat.Kotal_Khan }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3942)
at android.app.Activity.startActivityForResult(Activity.java:3889)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at android.app.Activity.startActivity(Activity.java:4213)
at android.app.Activity.startActivity(Activity.java:4181)
at com.example.jmac.mortalkombat.CharPage$1.onClick(CharPage.java:37)
at android.view.View.performClick(View.java:5197)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

First make sure you have an Activity in your project that has this name "Kotal_Khan" and is under the package "com.example.jmac.mortalkombat" since this is what you declared in your manifest.
Second Replace.
Intent intent = new Intent("com.example.jmac.mortalkombat.Kotal_Khan");
for
Intent intent = new Intent(getApplicationContext(), YOURCLASSNAME.class);
i assume will be Kotal_Khan.class.
Good Luck.

#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_char_page);
button_kk= (Button) findViewById(R.id.buttonkk);
button_next = (Button) findViewById(R.id.button);
OnClickButtonListener();
}
public void OnClickButtonListener() {
{
button_kk.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.jmac.mortalkombat.Kotal_Khan");
startActivity(intent);
}
}
);
button_next.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.jmac.mortalkombat.CharPage2");
startActivity(intent);
}
}
);
}

Related

Broadcast Receiver is not registering in android oreo

SmsBroadcastReceiver was not triggering when i received otp in oreo. I have explicitly registered my receiver in fragment instead of not only in manifest.
public class MyFragment extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
intentFilter = new IntentFilter();
intentFilter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
smsBroadcastReceiver = new SmsBroadcastReceiver();
getActivity().registerReceiver(smsBroadcastReceiver,intentFilter);
return inflater.inflate(
R.layout.fragment_two, container, false);
}
}
Here it's my SmsReceiverBroadcast class
public class SmsBroadcastReceiver extends BroadcastReceiver {
public SmsBroadcastReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
Log.d("onRecieve","Otp has been received");
}
} catch (Exception e) {
}
}
}
And in my manifest,
<receiver
android:name=".receiver.SmsBroadcastReceiver"
android:enabled="true"
android:exported="false"
>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
I'm not getting any trigger in override onReceive() method for the Broadcast receiver. I have found that we need to register a broadcast receiver explicitly. I register my receiver using registerBroadcast().It is not working for me.Also, I referred https://developer.android.com/about/versions/oreo/background.html
I have also tried
Do I need to add any other permission to register and triggering the receiver whenever I receive otp?Is my intent filters action(Telephony.Sms.Intents.SMS_RECIEVED_ACTION) correct?

RevMob no ads are displayed

I just update revmob with the last sdk (7.3.2) for Unity. I'm using Unity 4.5 Pro. Everything seems to work fine except that the ads isn't displayed. The debug say that the banner ad is displayed...but there is nothing on the screen and nothing to click either....Also I never get any Eula Popup at the launch of the game.
I think that I didn't missed anything in the doc (I maybe missed something that is why I need your help). All seems to be set as it said. I'm not using Proguard so I haven't do the googleplayservice proguard steps.
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:theme="#android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0" package="com.bas.revmobtesting" android:installLocation="preferExternal">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false">
<activity android:label="#string/app_name" android:name="com.bas.revmobtesting.UnityPlayerNativeActivity" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
<activity android:configChanges="keyboardHidden|orientation" android:name="com.revmob.ads.fullscreen.FullscreenActivity" android:theme="#android:style/Theme.Translucent">
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="20" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
here's the simple script:
public class RevMobTesting : MonoBehaviour, IRevMobListener
{
private static readonly Dictionary<String, String> REVMOB_APP_IDS = new Dictionary<String, String> () {
{ "Android", "My_ANDROID_ID"},
{ "IOS", "My_IOS_ID" }
};
private RevMob revmob;
void Awake ()
{
revmob = RevMob.Start (REVMOB_APP_IDS, gameObject.name);
revmob.SetTestingMode (RevMob.Test.WITH_ADS);
revmob.PrintEnvironmentInformation ();
}
private void Start ()
{
#if UNITY_ANDROID || UNITY_IPHONE
RevMobBanner banner = revmob.CreateBanner ();
banner.Show ();
#endif
}
#region IRevMobListener implementation
public void SessionIsStarted ()
{
Debug.Log ("Session started.");
}
public void SessionNotStarted (string revMobAdType)
{
Debug.Log ("Session not started.");
}
public void AdDidReceive (string revMobAdType)
{
Debug.Log ("Ad did receive.");
}
public void AdDidFail (string revMobAdType)
{
Debug.Log ("Ad did fail.");
}
public void AdDisplayed (string revMobAdType)
{
Debug.Log ("Ad displayed.");
}
public void UserClickedInTheAd (string revMobAdType)
{
Debug.Log ("Ad clicked.");
}
public void UserClosedTheAd (string revMobAdType)
{
Debug.Log ("Ad closed.");
}
public void InstallDidReceive (string message)
{
Debug.Log ("Install received");
}
public void InstallDidFail (string message)
{
Debug.Log ("Install not received");
}
public void EulaIsShown ()
{
Debug.Log ("Eula is displayed");
}
public void EulaAccepted ()
{
Debug.Log ("Eula was accepted");
}
public void EulaRejected ()
{
Debug.Log ("Eula was rejected");
}
#endregion
}
Thanks in advance,
David
Don't know you solved the issue or not. I got the same problem when upgraded to 7.3.2. I used to use this line to create banner:
banner = revmob.CreateBanner(RevMob.Position.BOTTOM);
In 7.3.2, "AdDisplayed" event triggered, but no banner showing. Finally, I succeeded to summon the banner with codes like:
int bannerWidth = (int) Screen.width;
cost float bannerRatio = 6.4f;
int bannerHeight = (int) (Screen.width / bannerRatio);
banner = revmob.CreateBanner(RevMob.Position.TOP,
0, (int)(Screen.height - bannerHeight),
bannerWidth, bannerHeight);
It seems Position.BOTTOM doesn't work in 7.3.2. I'm also waiting for RevMob's reply.

NewActivity not resolving in base class - should/how do I get the base class to recognize it?

Using Eclipse on OSX:
I'm trying to start my first new activity from an Intent. The error seems to be here:
Intent newButton = new Intent(v.getContext(),RandomActivity.class);
startActivity(RandomActivity);
RandomActivity isn't getting resolved. I think I have it correct in my Manifest file. I think my imports are correct. Do I need to declare it somewhere in my base Activity? That doesn't seem to work. It's like the code doesn't recognize the existence of the new class, but I can't see where to fix that.
The rest of my code:
package course.examples.UI.Button;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import course.examples.UI.Button.R;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import course.examples.UI.Button.RandomActivity;
public class ButtonActivity extends Activity {
int count = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent newButton = new Intent(v.getContext(),RandomActivity.class);
startActivity(RandomActivity);
^Multiple markers at this line
brandNewButton cannot be resolved to a type
RandomActivity cannot be resolved to a variable
Note: brandNewButton WAS a class, but I deleted it, then went File->New->Class to create RandomActivity.java.
}
});
}
}
My XML code is below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button
android:id="#+id/button"
android:text="Press Me!"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
>
</Button>
</RelativeLayout>
And here's my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.examples.UI.Button"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<application
android:allowBackup="false"
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".ButtonActivity"
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=".RandomActivity">
</activity>
</application>
</manifest>
Thanks in advance everyone, it's great to have such a community of support here for us noobies.
You don't really need to do :
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent newButton = new Intent(v.getContext(),RandomActivity.class);
Here's the issue: You are trying to start activity with different intent name ??
"startActivity(RandomActivity);" // Wrong intent name
Check your intent!
Instead, just try using this :
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent newButton = new Intent(ButtonActivity.this, RandomActivity.class);
startActivity(newButtom);//This is right
Also.. if your RandomActivity is not from your same package, register it with full path like:
<activity android:name="your packagename where random activity is.RandomActivity" />
Hope this helps.

Start Activity Intent from Android Application

I have an activity that holds a handler that I need to be running for the whole app. What I need to do is call the handler activity whenever main activity starts up, then upon executing a function at handler activity, handler activity should start the intent into second activity.
This is my code:
public class MyApp extends Application {
public void onCreate() {
h = new Handler() {
#Override
public void handleMessage(Message msg) {
Bundle b = msg.getData();
Log.d("tag",b.getString("msg"));
//THIS IS WHERE I WANT TO OPEN SECONDACTIVITY
}
};
}
}
MyApp is a global Application class I use to run a socket connection across the whole app. It needs to be alive as long as the app is running.
Its simple
Intent intent = new Intent(YourActivityClass.this, SECONDACTIVITY.class);
startActivity(intent);
public class MyApp extends Application {
public void onCreate() {
h = new Handler() {
#Override
public void handleMessage(Message msg) {
Bundle b = msg.getData();
Log.d("tag",b.getString("msg"));
Intent myIntent = new Intent(this, YourSecondActivity.class);
startActivity(myIntent);
}
};
}
}
Also add this to your manifest file
<activity android:name=".YourSecondActivity" />
Well, It turns out that I need to add: i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent i = new Intent(MyApp.this, SecondActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Because From MainActivity, I called MyApp (An class to maintain global application state). Then in MyApp, I process something and then I call SecondActivity.
First You add the activity information in AndroidManifest.xml LIKE
<activity
android:name="com.assignment.matchnumber.PlayActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.assignment.matchnumber.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Then put this in your MyApp activity where you want.
Intent openPlayActivity = new Intent("com.assignment.matchnumber.PLAY");
startActivity(openPlayActivity);
thanks
--Sajib

PayPal Error - Please make sure all fields have been entered

I have a problem in creating a working PayPal button in Sandbox environment.
After entering my email and password in the sandbox environment.
This is what I see.
Here are my codes
AndroidManifest.xml
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MypaypalActivity"
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.paypal.android.MEP.PayPalActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>
MypaypalActivity
public class MypaypalActivity extends Activity implements OnClickListener{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout MainLayout= new LinearLayout(this);
setContentView(R.layout.main);
PayPal pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_SANDBOX);
LinearLayout layoutSimplePayment = new LinearLayout(this);
layoutSimplePayment.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);
CheckoutButton COButton = pp.getCheckoutButton(this, PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);
COButton.setOnClickListener(this);
layoutSimplePayment.addView(COButton);
MainLayout.addView(layoutSimplePayment);
setContentView(MainLayout);
}
public void onClick(View v) {
PayPalPayment payment = new PayPalPayment();
payment.setSubtotal(new BigDecimal("10"));
payment.setCurrencyType("USD");
payment.setRecipient("becozofeuu_92#hotmail.com");
// payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
startActivityForResult(checkoutIntent, 1);
}
I faced same problem, finally I solve it using this code to
pass integer value to Bigdecimal
payment.setSubtotal(new BigDecimal("10"));
instead of using:
payment.setSubtotal(new BigDecimal(10));
e.g.:
public void onClick(View v) {
PayPalPayment payment = new PayPalPayment();
payment.setSubtotal(new BigDecimal("10"));
payment.setCurrencyType("USD");
payment.setRecipient("becozofeuu_92#hotmail.com");
// payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
startActivityForResult(checkoutIntent, 1);
}