0

Just started coding, be easy on me.

Followed the instructions outlined HERE but changed the button onClick to an ImageView onClick (I have an image that once clicked, moves to another activity) but it doesn't seem to work. I'm wondering if I'm missing something. If anyone could help me out, that would be awesome :)

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    ImageView hotel; **//the image that gets clicked. Don't know if i need
 //this in the code or not. nothing seems to point to it

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(null);
    }

    public void goToHotelWebView (View view) {
        Intent intent = new Intent(this, hotelwebview.class);
        startActivity(intent); **//The code that I added in from the tutorial**

    }
    @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 action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);


        }
    }

And on my .xml page, the image has onClick set to goToHotelWebView.

Thanks for your help!

EDIT= HERE IS THE ERROR IN LOGCAT... Reading it, it looks like a problem with the action bar design but I created a new activity with a blank slate and the app still crashes.

FATAL EXCEPTION: main
                                                                           Process: com.example.wes.tripedia2, PID: 24180
                                                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wes.tripedia2/com.example.wes.tripedia2.hotelwebview}: 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.
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                               at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                               at android.os.Looper.loop(Looper.java:164)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                            Caused by: 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.
                                                                               at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:201)
                                                                               at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
                                                                               at com.example.wes.tripedia2.hotelwebview.onCreate(hotelwebview.java:18)
                                                                               at android.app.Activity.performCreate(Activity.java:7000)
                                                                               at android.app.Activity.performCreate(Activity.java:6991)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                                                                               at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                               at android.os.Looper.loop(Looper.java:164) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:6494) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Zoe
  • 27,060
  • 21
  • 118
  • 148
wesdaco
  • 19
  • 1

1 Answers1

0

ERROR DESCRIPTION : 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.

Check your AndroidManifest file and check the theme for your activity "hotelwebview".

  <activity
            android:name=".hotelwebview"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:theme="@style/AppTheme"/>

Modify your theme like this :

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
diegoveloper
  • 93,875
  • 20
  • 236
  • 194