How can i solve this java lang error? - java

I am trying to solve this java lang error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sebasdeldihotmail.mediocre11/com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity}: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2039)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2153)
at android.app.ActivityThread.access$700(ActivityThread.java:137)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5031)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2030)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2153)
            at android.app.ActivityThread.access$700(ActivityThread.java:137)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5031)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
            at dalvik.system.NativeStart.main(Native Method)
i have checked again and again the code and i can't find what is making the app crash, maybe some fresh eyes can help to find the issue.
Here is the SignUpOrSignIn class
public class SignUpOrLogInActivity extends Fragment {
private static final String TAG = "MainFragment";
Button signIn;
Button signUp;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.signinorsignup_activity,container,false);
Button signIn = (Button)root.findViewById(R.id.login);
signIn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(getActivity(), LoginActivity.class));
}
});
Button signUp = (Button)root.findViewById(R.id.signup);
signUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(getActivity(),SignUpActivity.class));
}
});
return root;
}
private void onSessionStateChange(Session session, Session state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
}
and here is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#67AAE4">
<Button
android:id="#+id/signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
</LinearLayout>
MANIFEST
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name=".SignUpOrLogInActivity"
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=".DispatchActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name="com.facebook.LoginActivity"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
</application>
</manifest>
"CORRECTED MANIFEST"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sebasdeldihotmail.mediocre11" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
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=".DispatchActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name="com.facebook.LoginActivity"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
</application>
</manifest>
Can anyone figure out what is making the app crash?
Thanks very much for reading :)

Your SignUpOrLogInActivity extends Fragment. I'm assuming, based on the name, that this class is declared in the manifest as an Activity, which makes Android expect it to be a sub-class of Activity.
A Fragment must be contained in an Activity, so you need to create a class that extends Activity and contains your Fragment (which I would rename to something that doesn't contain the word Activity, since it's confusing). Your Android manifest should declare that activity class as the activity from which your app is launched.

SignUpOrLogInActivity extends Fragment
this is a fragment, and you are casting it to an activity.
You need to typecast it to a fragment for it to work
Caused by: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity

Related

Issues with "R.” in Android Studio

already performed clean project, rebuild project, analysed and inspected code but it does not resolve the issue. This started when making "Slash Screen" i check my XML files it looks good to me, but started to realize in every .Java class i created symbol R. was underlined with red try everything i can think of....
`package com.example.dom.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splashscreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread() {
public void run() {
try
{
sleep(4000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent myactivity = new Intent("com.example.dom.MAINACTIVITY");
startActivity(myactivity);
}
}
};
timer.start();
}
}`
Here's my Splash layout
<?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:background="#drawable/front"
>
</LinearLayout>
Here's my LogCat
04-27 18:27:49.869 12888-12888/? E/Zygote: MountEmulatedStorage()
04-27 18:27:49.869 12888-12888/? E/Zygote: v2
04-27 18:27:49.879 12888-12888/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
04-27 18:27:55.679 12888-12945/com.example.dom.myapp E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0
Here's my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dom.myapp">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ActivityOne"></activity>
<activity android:name=".ActivityTwo"></activity>
<activity android:name=".ActivityThree"></activity>
<activity android:name=".ActivityFour"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
In splash layout do this
android:background="#+id/drawable/front" must be android:background="#drawable/front" remove this #+id/
looks like this:
<?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:background="#drawable/front"
>
</LinearLayout>

Android application failed to start activity

I want to know why it cannot open up new java class.
When I try to start new activity, it will be crash.
public class MainActivity extends ActionBarActivity {
EditText emailEt;
TextView registerET;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailEt = (EditText) findViewById(R.id.email);
registerET = (TextView) findViewById(R.id.register);
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
MainActivity.this.finish();
}
});
}
public void OnLogin(View view) {
String username = emailEt.getText().toString();
String type = "login";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, username);
}
}
It's possible manifests problem? Am I put it wrong position for the activity?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
</application>
<activity android:label="#string/app_name" android:name=".RegisterActivity"/>
</manifest>
It look like can be open up new java class, but it still display MainActivity.
Error Log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a20_1discussboard, PID: 2194
java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatTextView with id 'register'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Put proper Menifest format:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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:label="#string/app_name"
android:name=".RegisterActivity"/> //<---here
</application>
</manifest>
Don't call finish(), this caused your crash:
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
//remove finish();
}
});
Try declared activity in application in your AndroidManifest.xml like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
</manifest>
Be sure that you add RegisterActivity to your AndroidManifest.xml inside <application> tag:
<application ...>
...
<activity
android:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
Delete this line from onCreate method: MainActivity.this.finish();
If you want to stop or pause MainActivity, use:
#Override
public void onPause() { }
or
#Override
public void onStop() { }
in MainActivity class.
Thanks all.
Add RegisterActivity to AndroidManifest.xml inside <application> tag and remove MainActivity.this.finish()
It is working now.

on Click function does not work in my application

I am trying to show another activity by clicking a button with Intent class but it stills gives error which is
" unfortunately my application has stopped"
and I think the code is correct
this is the `main activity class
course=(EditText) findViewById(R.id.editText);
hour=(EditText) findViewById(R.id.editText1);
add= (Button) findViewById(R.id.button);
view_= (Button) findViewById(R.id.button1);
view_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,ViewActivity.class);
startActivity(intent);
}
});
}
}
and this is ViewActivity class
TextView tv;
Button ed, de, view_;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
tv = (TextView) findViewById(R.id.details);
ed = (Button) findViewById(R.id.ed);
de = (Button) findViewById(R.id.delete);
view_= (Button) findViewById(R.id.button1);
Intent intent = getIntent();
view_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
In additional I had added the .ViewActivity on the AndroidManifest.xml
<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=".ViewActivity" />
</application>'
locat >>
FATAL EXCEPTION: main
Process: com.example.android.intent, PID: 11316
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.intent/com.example.android.intent.ViewActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.android.intent.ViewActivity.onCreate(ViewActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
view layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="80dp"
android:layout_height="50dp" >
<TextView
android:text="Course"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="#+id/course"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textSize="24sp" />
<TextView
android:text="Hour"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="#+id/hour"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:layout_marginRight="30dp" />
</TableRow>
</TableLayout>
<Button
android:text="Edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="45dp"
android:id="#+id/ed"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="38dp"
android:layout_marginStart="38dp"
android:onClick="" />
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="19dp"
android:layout_marginEnd="19dp"
android:id="#+id/delete"
android:layout_alignBaseline="#+id/ed"
android:layout_alignBottom="#+id/ed"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="" />
<TextView
android:layout_width="350dp"
android:layout_height="350dp"
android:id="#+id/details"
android:layout_above="#+id/delete"
android:layout_centerHorizontal="true" />
<Button
android:text="Refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/delete"
android:layout_toLeftOf="#+id/delete"
android:layout_toStartOf="#+id/delete"
android:layout_marginRight="28dp"
android:layout_marginEnd="28dp"
android:id="#+id/button4"
android:onClick="" />
Can anyone help , thanks :)
Change your manifest like this,You added the ViewActivity inside another activity.
<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 = ".ViewActivity"/>
</application>'
Add this to your view layout,
<Button
android:text="Close View Activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button1" />
You haven't close the activity tag. Change AndroidManifest.xml to:
<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=".ViewActivity">
</activity>
</application>
Change this
view_= (Button) findViewById(R.id.button1);
To
view_= (Button) findViewById(R.id.button4);
There is no Button button1 in your ViewActivity class's XML, so when you try to access button1, NullPointerException occurs.
Try this in your manifest. You put one activity in another. Put seperate.
<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=".ViewActivity" />
</application>

Unfortunately, APP Has Stopped after added ADMOB

I am trying to add adMob ad in my android application, but it gives me unfortunately stopped error,
I am not expert in android program so dont know whats wrong in aap.
HomeActivity
package com.innobee.finddifferences;
import com.google.android.gms.ads.*;
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 com.innobee.finddifferences.utility.Prefs;
public class HomeActivity extends Activity{
private int mLevelDuration; //Max Duration of the level in seconds
private Button mBtnResume;
private Button mBtnStart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
mLevelDuration = getResources().getInteger(R.integer.levelDuration);
mLevelDuration = mLevelDuration * 1000;
mBtnStart = (Button)findViewById(R.id.btnStart);
mBtnStart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Prefs.clearPref(getApplicationContext());
Prefs.setStagePref(getApplicationContext(), 1);
Intent play = new Intent(HomeActivity.this,
PlayActivity.class);
startActivity(play);
}
});
mBtnResume = (Button)findViewById(R.id.btnResume);
mBtnResume.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent play = new Intent(HomeActivity.this,
PlayActivity.class);
startActivity(play);
}
});
if(Prefs.getResumePref(getApplicationContext()) == mLevelDuration) {
mBtnResume.setVisibility(View.INVISIBLE);
}
else {
mBtnResume.setVisibility(View.VISIBLE);
}
}
#Override
protected void onRestart() {
super.onRestart();
//Show/hide resume button
if(Prefs.getResumePref(getApplicationContext()) == mLevelDuration) {
mBtnResume.setVisibility(View.INVISIBLE);
}
else {
mBtnResume.setVisibility(View.VISIBLE);
}
}
}
activity_home
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:background="#drawable/background"
android:gravity="bottom"
android:orientation="vertical" >
<Button
android:id="#+id/btnStart"
android:layout_width="209dip"
android:layout_height="55dip"
android:layout_marginBottom="30dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_start" />
<Button
android:id="#+id/btnResume"
android:layout_width="209dip"
android:layout_height="55dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_resume"
android:layout_marginBottom="50dip"
android:visibility="gone" />
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-1504309466120108/6661079420"
ads:adSize="BANNER"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.innobee.finddifferences"
android:versionCode="4"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme.NoTitle" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name="com.innobee.finddifferences.HomeActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
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.innobee.finddifferences.NextGameActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.Transparent"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.SummaryActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.LostActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.StagePickActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.PlayActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.ListMobileActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
LogCat
11-30 22:52:47.121: E/AndroidRuntime(1282): at com.innobee.finddifferences.HomeActivity.onCreate(HomeActivity.java:21)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.Activity.performCreate(Activity.java:5104)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-30 22:52:47.121: E/AndroidRuntime(1282): ... 11 more
11-30 22:52:47.121: E/AndroidRuntime(1282): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: /data/app/com.innobee.finddifferences-1.apk
11-30 22:52:47.121: E/AndroidRuntime(1282): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
11-30 22:52:47.121: E/AndroidRuntime(1282): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-30 22:52:47.121: E/AndroidRuntime(1282): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-30 22:52:47.121: E/AndroidRuntime(1282): ... 21 more
Thank you
The error might come from the wrong activity, you listed in your manifest, use this one:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
Still, as I said in my comment you should use minSDK="9" with the latest version of Google Services, otherwise this can lead to problems as well

Android - ClassNotFoundException (TwitterAPI)

Okay so I've been messing around with the Twitter API, and all of a sudden I've started to get the ClassNotFoundException error code when I try and enter the Activity which has my login box to sign into Twitter.
Here's the error code.
2398-2398/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
07-05 02:19:30.138 2398-2398/josh.com.twitterapi E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: josh.com.twitterapi.LoginActivity
at josh.com.twitterapi.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:204)
at josh.com.twitterapi.NavigationDrawerFragment.access$000(NavigationDrawerFragment.java:32)
at josh.com.twitterapi.NavigationDrawerFragment$1.onItemClick(NavigationDrawerFragment.java:99)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView$1.run(AbsListView.java:3973)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
07-05 02:21:03.973 3223-3223/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
This is my LoginActivity.java.
package josh.com.socialme;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.codepath.oauth.OAuthLoginActivity;
public class LoginActivity extends OAuthLoginActivity<TwitterClient> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
// Inflate the menu; this adds items to the action bar if it is present.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
// OAuth authenticated successfully, launch primary authenticated activity
// i.e Display application "homepage"
#Override
public void onLoginSuccess() {
// Intent i = new Intent(this, PhotosActivity.class);
// startActivity(i);
}
// OAuth authentication flow failed, handle the error
// i.e Display an error dialog or toast
#Override
public void onLoginFailure(Exception e) {
e.printStackTrace();
}
// Click handler method for the button used to start OAuth flow
// Uses the client to initiate OAuth authorization
// This should be tied to a button used to login
public void loginToRest(View view) {
getClient().connect();
}
}
This is my AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
And this is my method I use to get to the activity.
private void selectItem(int position) {
// Handle Navigation Options
Intent intent;
switch (position) {
case 1:
intent = new Intent(getActivity(), Feed.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
case 2:
intent = new Intent(getActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
}
}
I would greatly appreciate it if someone could point me towards the right direction.
Kind regards,
Josh
(AndroidManifest.xml as requested)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_login_activity" >
</activity>
</application>
</manifest>

Categories