2

So I'm incredibly new to Android studio. I typically just watch tutorials and follow along to learn what everything is and see how everything works. I was trying to follow a tutorial for a card view/recycler view with a collapsilbe toolbar, and after finishing the code (almost exactly as the guy in the video showed), the app still won't run. Only thing I changed were icon, a couple drawables and some of the values (I edited it all around in the code).

Here's the post of the source code I followed: https://github.com/delaroy/AndroidCardView?files=1

As I said, there's no errors or anything. But when I run the app, it crashes immediately.

This is also my first post, so if any other info is needed, let me know.

As I said, I changed only pictures and a few names of the variables and such. Also, everything that was changed was fixed in values and such.

I've ran other apps on my phone with no issue.

Not sure if it's a phone issue or what.

I'm using a Note 3 running Android 5.0.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Xxero
  • 31
  • 1
  • 1
  • 2
  • 1
    You really should read [ask] before you post a question. This question is almost certainly going to be closed as off topic because you A) have not posted any of your source code and B) have not shown the error message you're getting. – Tibrogargan Sep 14 '16 at 02:58
  • The GitHub page I posted is essentially the exact code I'm using. As I said, the only thing I changed were some names of variables and some drawables. Also, the error I'm getting (as I said again) is nonexistent. I'm not getting an error. The app crashes when trying to open. It's simply a "unfortunately, ___ has closed". – Xxero Sep 14 '16 at 02:59
  • You changed something that broke the code and expect people to randomly guess what it was you did? – Tibrogargan Sep 14 '16 at 03:00
  • I only changed the names of variables and drawables though. All of which were fixed. If they weren't, there would be an error somewhere, correct? – Xxero Sep 14 '16 at 03:02
  • 1
    Who knows? Maybe you changed a variable name that was being referenced from somewhere else. It doesn't really matter, Stack Overflow requires you to post your source and the error when asking for debugging help. No use bitching about it – Tibrogargan Sep 14 '16 at 03:07
  • As I said, I'm new to all of this. I wouldn't even know how to save the source or post it. This is the biggest/most complicated/most detailed app I've tried to run. It's also the only one that hasn't been able to run. That's why I'm confused. Idk if it's maybe an error when I'm running it, or if it's with my phone. I also don't know how to check those things to see. – Xxero Sep 14 '16 at 03:07
  • 2
    Literally in the title it says "No errors". How do I post an error I'm not getting? – Xxero Sep 14 '16 at 03:08
  • 1
    Did you try reading this post? http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – OneCricketeer Sep 14 '16 at 03:51

3 Answers3

1

Sometimes it occurs due to repeating of ID from xml file, example, if you have two xml files such Main activity and Home, both you have Textview with id myTextview, so once use this(id) in you class, android studio will not count as error but apps will crash at both activity once you click.' Enyoy Coding.

Mr.Banza
  • 11
  • 1
0

You must check the Log to see what is the exception which caused the crash. In the log (lower part of the IDE) there will be the name of the Exception, the element which launched it and also there will be the links to the lines of the code where the problem was found.

If you still can't find the error this way, you can set breakpoints at the left of the lines of code where you want the application stops during debug, and then run the app in the debug mode to see exactly what happens.

Another tip: often, when I was sure about the rightness of my code and it runs but crashes, it's about having declared all the Activities in the manifest (or all the Services) and to have set all required permission. Because in this case there are no apparent errors before running the app. Let us know!

Alessandro Argentieri
  • 2,901
  • 3
  • 32
  • 62
  • E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xxerosec.fldoccs, PID: 10093 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxerosec.fldoccs/com.xxerosec.fldoccs.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. This is what I'm seeing. – Xxero Sep 14 '16 at 17:01
  • I also just got this when opening the main activity: Rendering Problems The following classes could not be instantiated: - android.support.design.widget.CollapsingToolbarLayout (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details android.content.res.Resources$NotFoundException   at com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:626) Copy stack to clipboard – Xxero Sep 14 '16 at 17:04
  • ok as I can see it could be about your action bar. The nice thing is that Android Studio suggests how to fix problems. It tells you to use a toolbar instead. Now I post another answer with some info about it. – Alessandro Argentieri Sep 15 '16 at 08:25
0

Ok, it could be about Toolbar, let's see how it works.

In android is better using the widget toolbar instead of actionbar because...

To do that you must add (if there is not) the appcompact v7 library in Gradle (module:app), just like this:

dependecies {  compile 'com.android.support:appcompat-v7:+'  }

To remove the action bar and insert a toolbar you must:

 1. remove actionbar from manifest setting a no actionbar style:
     <application
          android:theme="@style/Theme.AppCompact.Light.NoActionBar"
      />

 2. insert Toolbar widget into the layout of the activity:
     <LinearLayout ...>
          ...
          <android.support.v7.widget.Toolbar
               android:id="@+id/mytoolbar"
               android:layout_width="match_parent"
               android:layout_height="?attr/actionBarSize"
               android:background="?attr/colorPrimary"
               android:elevation="8dp"
               android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
               android:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

          </LinearLayout>

 3. insert the widget into the activity and set it as support toolbar:
      @Override
     protected void onCreate(Bundle savedInstanceState){
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
           Toolbar myToolbar = (Toolbar) findViewById(R.id.mytoolbar);
           myToolbar.setLogo(R.mipmap.ic_launcher);
           myToolbar.setTitle("Titolo");
           myToolbar.setSubtitle(R.string.sottotitolo);
           setSupportActionBar(myToolbar);
     }

 4. create a menù for the Toolbar, into res>menu
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
      android:icon="@drawable/ic_new_game"
      android:title="@string/new_game"
      android:showAsAction="ifRoom"/>
    <item android:id="@+id/help"
      android:icon="@drawable/ic_help"
      android:title="@string/help"
      android:showAsAction="never"/>
    <item android:id="@+id/tutorials"
      android:icon="@drawable/ic_tuts"
      android:title="@string/tutorials"
               android:showAsAction="always"/>
     </menu>

 5. bind menù to toolbar through the two methods into the activity:


@Override
public boolean onCreateOptionsMenu(Menu menu){
     //Inflate the menu; this adds items to the action bar if it is present
     getMenuInflater().inflate(R.menu.menu_main, menu);
     return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.new_game:
            newGame();
            return true;
        case R.id.help:
            showHelp();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Alessandro Argentieri
  • 2,901
  • 3
  • 32
  • 62