2017-03-29 11 views
0

私は見たtv-showを追跡するAndroidスタジオでアプリケーションを作成しています。しかし、EditShowActivityを起動しようとすると、リストビュー内の項目をクリックすると、電話アプリがクラッシュします。私は理由や方法を理解できません。私EditShowActivityへeditActivityページを読み込めません

コール

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

       Intent intent = new Intent(MainActivity.this, EditShowActivity.class); 
       intent.putExtra(EXTRA_SHOW_ID, showArrayAdapter.getItem(position).getId()); 
       startActivityForResult(intent, 2);   } 
     }); 

これは私のEditShowActivity

public class EditShowActivity extends AppCompatActivity { 
    private Show show; 
    private DataSource datasource; 
    private EditText editText; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_edit); 

     datasource = new DataSource(this); 
     long showId = getIntent().getLongExtra(MainActivity.EXTRA_SHOW_ID, -1); 
     show = datasource.getShow(showId); 

     TextView textView = (TextView) findViewById(R.id.details_textview); 
     textView.setText(show.getShow()); 

     editText = (EditText) findViewById(R.id.details_updateText); 

     Button updateButton = (Button) findViewById(R.id.details_updateButton); 

     updateButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       show.setShows(editText.getText().toString()); 
       datasource.updateShow(show); 
       Toast.makeText(EditShowActivity.this, "Assignment Updated", Toast.LENGTH_SHORT).show(); 

       Intent resultIntent = new Intent(); 
       setResult(Activity.RESULT_OK, resultIntent); 
       finish(); 
      } 

     }); 
    } 
} 

マイactivity_edit.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.kevin.androidapp.EditShowActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 

      app:popupTheme="@style/AppTheme.PopupOverlay" /> 



    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_edit" /> 



</FrameLayout> 

マイcontent_edit.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_edit"> 

    <TextView 
     android:id="@+id/details_textview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="44dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="10dp"> 

     <EditText 
      android:id="@+id/details_updateText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <Button 
      android:id="@+id/details_updateButton" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:onClick="addListItem" 
      android:text="Update" /> 

    </LinearLayout> 



</RelativeLayout> 
です
+0

あなたが投稿する例外のログを持っていますか? – samosaris

+0

私は恐れていない、私は私の携帯電話でそれを実行しています。ログがありません – KevinTheGreat

+3

SDKが正しくインストールされていますか?電話機をワークステーションに接続し、ADBを使用して電話機に接続して(Settings-> Developerオプションで「USBデバッグ」が有効になっている必要があります)、android-sdk \ tools \ ddms.batを実行してください。セットアップには十分な価値があります。ロガーはたくさんの良い情報を表示します。 – samosaris

答えて

0

あなたは試みることができる:

その後、
intent.putExtra(MainActivity.EXTRA_SHOW_ID, (long) showArrayAdapter.getItem(position).getId()); 

long showId = (long) getIntent().getLongExtra(MainActivity.EXTRA_SHOW_ID, -1); 
+0

私は同じ結果を得ました。 – KevinTheGreat

関連する問題