-3

Please i am trying to change my launcher Activity to an authentication Activity i just developed using twitter digits, i already made the necessary adjustment in my android manifest and java code but noticed that the app keeps crashing each time i attempt to launch,the name of the authentication Activity is AboutAcivity.java, during the debugging session, i observed from my android monitor console that this line highlighted in blue at com.close.close.AboutActivity.onCreate(AboutActivity.java:34) always point to setContentView(R.layout.activity_about); i have inspected that layout and find nothing wrong, i guess i need a third eye to help crush this annoying bug, Note, i already reviewed other staackoverflow questions but the solution there did not work for me. Thank you.

here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.close.close"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission
        android:name="android.permission.CAMERA"
        android:required="true"/>

    <uses-feature android:name="android.hardware.camera.any"/>

    <android:uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme">
        <service
            android:name=".MessageService"
            android:enabled="true"/>

        <activity
            android:name=".AboutActivity"
            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.theartofdev.edmodo.cropper.CropImageActivity"/>
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="34308698bb3cbc96444f2ff10ad1ae167d75d8e9"/>

        <activity android:name=".MainActivity">
        </activity>
        <activity android:name=".Profile_info">
        </activity>



        <activity
            android:name=".ChatActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_chat"
            android:launchMode="singleTop">
        </activity>
        <activity
            android:name=".ViewImageActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_view_image"
            android:parentActivityName=".ChatActivity"
            android:theme="@style/FullscreenTheme">
        </activity>
        <activity
            android:name=".RecordAudioActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_record_audio"
            android:parentActivityName=".ChatActivity">
        </activity>
        <activity
            android:name=".PlayVideoActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_play_video">
        </activity>
        <activity
            android:name=".FilePickerActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_file_picker"
            android:parentActivityName=".ChatActivity">
        </activity>
        <activity
            android:name=".WebViewActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_web_view"
            android:parentActivityName=".ChatActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:scheme="myweburl"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".DrawingActivity"
            android:label="@string/title_activity_drawing">
        </activity>

    </application>

</manifest>

Here is the AboutActivity code

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.digits.sdk.android.AuthCallback;
import com.digits.sdk.android.Digits;
import com.digits.sdk.android.DigitsAuthButton;
import com.digits.sdk.android.DigitsException;
import com.digits.sdk.android.DigitsSession;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;

import io.fabric.sdk.android.Fabric;

public class AboutActivity extends AppCompatActivity {






    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new TwitterCore(authConfig), new Digits.Builder().build());
        setContentView(R.layout.activity_about);





        DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);

        digitsButton.setCallback(new AuthCallback() {
            @Override
            public void success(DigitsSession session, String phoneNumber) {
                // TODO: associate the session userID with your user model
                Toast.makeText(getApplicationContext(), "Authentication successful for "
                        + phoneNumber, Toast.LENGTH_LONG).show();

                Intent intent=new Intent(AboutActivity.this,Profile_info.class); // redirecting to LoginActivity.
                startActivity(intent);

            }

            @Override
            public void failure(DigitsException exception) {
                Log.d("Digits", "Sign in with Digits failure", exception);
            }
        });



    }
}

Here is my log cat

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.close.close/com.close.close.AboutActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2348)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
                      at android.app.ActivityThread.access$800(ActivityThread.java:151)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:135)
                      at android.app.ActivityThread.main(ActivityThread.java:5348)
                      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:947)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                      at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                      at com.close.close.AboutActivity.onCreate(AboutActivity.java:34)
                      at android.app.Activity.performCreate(Activity.java:6012)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410) 
                      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:135) 
                      at android.app.ActivityThread.main(ActivityThread.java:5348) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:372) 

Here is my activity_about.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#FD579D"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context="com.close.close.AboutActivity"
                android:orientation="horizontal">


    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="28dp"
        android:gravity="center_horizontal"
        android:text="@string/welcome"
        android:textColor="#FFFFFF"
        android:textSize="37sp"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="80dp"
        android:gravity="center_horizontal"
        android:text="@string/to"
        android:textColor="#FFFFFF"
        android:textSize="37sp"/>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="128dp"
        android:gravity="center_horizontal"
        android:text="@string/close"
        android:textColor="#FFFFFF"
        android:textSize="37sp"/>
    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="189dp"
        android:gravity="center_horizontal"
        android:text="@string/about"
        android:textColor="#FFFFFF"
        android:textSize="18sp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="50dp"
        android:weightSum="1"
        android:layout_marginStart="164dp"
        android:layout_below="@+id/textView4"
        android:layout_alignParentStart="true">


    </LinearLayout>


    <com.digits.sdk.android.DigitsAuthButton
        android:id="@+id/auth_button"
        android:layout_width="148dp"
        android:layout_height="48dp"
        android:background="@drawable/dgts__digits_btn"
        android:orientation="vertical"
        android:layout_marginTop="54dp"
        android:layout_below="@+id/textView4"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"/>


</RelativeLayout>
  • Did you read the error message? It tells you exactly what to do to fix the problem. Which part of the message did you not understand? We will be glad to help clarify. – Code-Apprentice Jul 31 '17 at 01:44
  • See https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity to answer your question. Note you would have found this much more quickly if you just google the error message. – Code-Apprentice Jul 31 '17 at 01:51

1 Answers1

1

Change this

public class AboutActivity extends AppCompatActivity {

to this

public class AboutActivity extends Activity {
Martin De Simone
  • 2,108
  • 3
  • 16
  • 30
  • The error message says `You need to use a Theme.AppCompat theme (or descendant) with this activity.` Are you sure that your answer would resolve this problem? – Tim Biegeleisen Jul 31 '17 at 01:40
  • 1
    Yes, that is why i post an answer – Martin De Simone Jul 31 '17 at 01:42
  • 1
    There may be a good reason to use `AppCompatActivity`. This solution does not actually address the problem mentioned in the error. – Code-Apprentice Jul 31 '17 at 01:46
  • In this case i dont see a reason to use AppCompat, only using an activity would fix the problem – Martin De Simone Jul 31 '17 at 01:47
  • It will fix the error, yes. But if the OP needs to use AppCompatActivity, then it doesn't really solve the entire problem. You should explain this in your answer as well as give a viable solution to continue to use AppCompatActivity if necessary. – Code-Apprentice Jul 31 '17 at 01:48
  • Furthermore, this is a dupe: https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – Code-Apprentice Jul 31 '17 at 01:49
  • @Code-Apprentice you are right, this in certain cases may not be a good solution, but in most cases it is. – Martin De Simone Jul 31 '17 at 01:51
  • I have no idea what "most cases" are. The real issue is to clarify whether or not the OP needs to support older devices with AppCompat. – Code-Apprentice Jul 31 '17 at 01:52
  • I faced this problem many times and i always solved it like this, and i am pretty sure that this will work for the OP. I have to admit that this is not ideal, but as an easy fix it works – Martin De Simone Jul 31 '17 at 01:56
  • So you are making apps for the most recent of Android. I guarantee you that there are many people making apps that must run on older devices and therefore need to use AppCompatActivity. There are other solutions to the problem that will allow this. In fact, the error message clearly states that other solution. – Code-Apprentice Jul 31 '17 at 01:58
  • I don't intend to post an answer here because this question has already been answer very thoroughly. See the link in one of my previous comments. – Code-Apprentice Jul 31 '17 at 02:15
  • @Emmanuelogbonna Note that alternatively, you can use `Theme.AppCompat` as suggested by the error message. – Code-Apprentice Jul 31 '17 at 02:21
  • @Code-aaprentice where am i suppose to use that, is it in the android manifest. – Emmanuel Okezie Ogbonna Jul 31 '17 at 02:41
  • @Emmanuelogbonna It was down voted because it only solves your error without explaining why nor offering other options. Feel free to read the above discussion. You should also read the two linked questions at the top of this page. One of them is the exact same as your own question and has several answers which show you exactly how to fix the problem. – Code-Apprentice Jul 31 '17 at 04:53
  • Another problem just came up related to this "error You need to use a Theme.AppCompat theme (or descendant) with this activity" before you ask i already spent hours reviewing the existing solutions on stackoverflow but non seems a fit, if you take a look at my manifest the theme is referenced this way "android:theme="@style/CustomActionBarTheme"> where as most solutions suggest using "android:theme="@style/Theme.AppCompat" >" . My case involves a customActionBarTheme. the problem arises each time i click an image uploading button in the app am developing any suggestion or help, – Emmanuel Okezie Ogbonna Jul 31 '17 at 07:44