画面遷移時にアプリがクラッシュしてしまいます。
ランチャービューを最初に表示し、次にトップビューに遷移しようとするとアプリ側で
アプリが停止しました
と表示されます。
ログなどは無しです。
ランチャービューから他のビューへの遷移は問題なくできます。
以下、コードです。
ランチャービュー
Kotlin
1package 弊社.android 2 3import android.content.Intent 4import android.support.v7.app.AppCompatActivity 5import android.os.Bundle 6import android.util.Log 7import java.util.* 8import kotlin.concurrent.schedule 9 10class COLauncherActivity : AppCompatActivity() { 11 12 override fun onCreate(savedInstanceState: Bundle?) { 13 super.onCreate(savedInstanceState) 14 setContentView(R.layout.activity_launcher) 15 } 16 17 override fun onStart() { 18 super.onStart() 19 20 Timer().schedule(0, 2000, { 21 goToTop() 22 this.cancel() 23 }) 24 } 25 26 fun goToTop() { 27 val intent: Intent = Intent(this, COTopActivity::class.java) 28 startActivity(intent) 29 } 30} 31
トップビュー
Kotlin
1package 弊社.android 2 3import android.content.Intent 4import android.os.Bundle 5import android.support.design.widget.Snackbar 6import android.support.design.widget.NavigationView 7import android.support.v4.view.GravityCompat 8import android.support.v7.app.ActionBarDrawerToggle 9import android.support.v7.app.AppCompatActivity 10import android.view.Menu 11import android.view.MenuItem 12import kotlinx.android.synthetic.main.activity_top.* 13import kotlinx.android.synthetic.main.app_bar_cotop.* 14 15class COTopActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { 16 17 override fun onCreate(savedInstanceState: Bundle?) { 18 super.onCreate(savedInstanceState) 19 setContentView(R.layout.activity_top) 20 setSupportActionBar(toolbar) 21 22 fab.setOnClickListener { view -> 23 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 24 .setAction("Action", null).show() 25 } 26 27 val toggle = ActionBarDrawerToggle( 28 this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close 29 ) 30 drawer_layout.addDrawerListener(toggle) 31 toggle.syncState() 32 33 nav_view.setNavigationItemSelectedListener(this) 34 } 35 36 override fun onBackPressed() { 37 if (drawer_layout.isDrawerOpen(GravityCompat.START)) { 38 drawer_layout.closeDrawer(GravityCompat.START) 39 } else { 40 super.onBackPressed() 41 } 42 } 43 44 override fun onCreateOptionsMenu(menu: Menu): Boolean { 45 // Inflate the menu; this adds items to the action bar if it is present. 46 menuInflater.inflate(R.menu.cotop, menu) 47 return true 48 } 49 50 override fun onOptionsItemSelected(item: MenuItem): Boolean { 51 // Handle action bar item clicks here. The action bar will 52 // automatically handle clicks on the Home/Up button, so long 53 // as you specify a parent activity in AndroidManifest.xml. 54 when (item.itemId) { 55 R.id.action_settings -> return true 56 else -> return super.onOptionsItemSelected(item) 57 } 58 } 59 60 override fun onNavigationItemSelected(item: MenuItem): Boolean { 61 // Handle navigation view item clicks here. 62 when (item.itemId) { 63 R.id.btn -> { 64 val intent = Intent(this, 別の画面のActivity::class.java) 65 startActivity(intent) 66 } 67 R.id.btn -> { 68 val intent = Intent(this, 別の画面のActivity::class.java) 69 startActivity(intent) 70 } 71 R.id.btn -> { 72 val intent = Intent(this, 別の画面のActivity::class.java) 73 startActivity(intent) 74 } 75 R.id.btn -> { 76 val intent = Intent(this, 別の画面のActivity::class.java) 77 startActivity(intent) 78 } 79 R.id.btn -> { 80 val intent = Intent(this, 別の画面のActivity::class.java) 81 startActivity(intent) 82 } 83 R.id.btn -> { 84 val intent = Intent(this, 別の画面のActivity::class.java) 85 startActivity(intent) 86 } 87 R.id.btn -> { 88 val intent = Intent(this, 別の画面のActivity::class.java) 89 startActivity(intent) 90 } 91 } 92 93 drawer_layout.closeDrawer(GravityCompat.START) 94 return true 95 } 96} 97
別のビューへは問題なく遷移できるので問題はこのビューだという事までは突き止められたのですが、ここからどうすればいいのか見当が付きません。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー