2017-11-23 8 views
0

코딩이 시작되었으므로 쉽게 할 수 있습니다.ImageView를 클릭하면 응용 프로그램이 충돌합니다.

HERE에 설명 된 지침에 따라 버튼 onClick을 ImageView onClick으로 변경했는데 (한 번 클릭 한 이미지가 다른 활동으로 이동 함) 작동하지 않는 것 같습니다. 내가 뭔가를 놓치고 있는지 궁금 하네. 누군가가 나를 도울 수 있다면, 그것은 좋지 않을까 :)

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); 
 

 

 
     } 
 
    }

그리고 내 .XML 페이지

, 이미지는 온 클릭은 goToHotelWebView로 변경됩니다.

도움 주셔서 감사합니다.

EDIT = LOGCAT에서 오류가 발생했습니다 ... 읽는 중, 작업 표시 줄 디자인에 문제가있는 것 같지만 빈 슬레이트로 새 활동을 만들었으며 앱이 계속 충돌합니다.

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) 

+0

당신이 'hotelwebview'를 선언 했습니까? – diegoveloper

+0

예. 앱 폴더를 마우스 오른쪽 버튼으로 클릭하고 "새 활동 추가"를 선택하여 AndroidManifest.xml의 hotelwebview를 자동으로 선언하도록 새 활동을 만들었습니다. – wesdaco

+0

logcat에 표시되는 오류는 무엇입니까? – diegoveloper

답변

0

오류 설명 : 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.

이 AndroidManifest를 파일을 확인하고 활동 "hotelwebview"에 대한 주제를 확인합니다.

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

은 다음과 같이 테마를 수정 : 당신의 AndroidManifest.xml에

<!-- 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> 
+1

정말 고마워요! 당신은 큰 도움이되었습니다. – wesdaco

+0

나는 내 오류를 찾기 위해 logcat을 확인하는 것을 배웠다. 문제가 내 도구 모음과 함께 나타나는 것 같습니다 – wesdaco

+0

이 답변으로 문제가 해결되면 허용 된 것으로 표시하는 것을 잊지 마십시오. – diegoveloper

관련 문제