2017-06-11 4 views
-2

新しいインテントを開くときはいつでもアプリがクラッシュし続けます。どちらもエラーは出ません。ただ停止します。新しいインテントを開こうとすると、自分のアプリがクラッシュし続けます

マイMainActivity:

package nl.mirjamvanmourik.hueemulator; 

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ListView; 

import java.io.IOException; 
import java.net.URL; 
import java.util.ArrayList; 

public class MainActivity extends AppCompatActivity implements 
LightBulbTaskListener, AdapterView.OnItemClickListener { 

private final Bridge bridge = Bridge.getInstance(); 
private final ArrayList<LightBulb> list = new ArrayList<>(); 

private ListView listView; 
private LightBulbAdapter adapter; 

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

    listView = (ListView) findViewById(R.id.lightBulbsList); 
    adapter = new LightBulbAdapter(this, list); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(this); 

    fetchLights(); 
    } 

    public void fetchLights(){ 
    try { 
     list.clear(); 
     URL[] url = new URL[]{ 
       new URL (getString(R.string.BASE_URL) + 
getString(R.string.USERNAME) + "/lights/") 
     }; 

     LightBulbTask.getLights w = new LightBulbTask.getLights(this); 
     w.execute(url); 
    } catch (IOException e) { 
     System.out.println("Error:> " + e); 
    } 
} 

public void newLightBulb(LightBulb light){ 
    list.add(light); 
    adapter.notifyDataSetChanged(); 
} 

@Override 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
    LightBulb light = (LightBulb) list.get(position); 
    Intent intent = new Intent(getApplicationContext(), 
LightBulbDetails.class); 
    intent.putExtra("LIGHTBULB", light); 
    startActivity(intent); 
} 
} 

マイLightBulbDetailsクラス:

package nl.mirjamvanmourik.hueemulator; 

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.widget.SeekBar; 
import android.widget.TextView; 

/** 
* Created by mirja on 10-6-2017. 
*/ 

public class LightBulbDetails extends AppCompatActivity { 

    private Bridge bridge = Bridge.getInstance(); 
    private LightBulb light; 
    private TextView label; 
    private SeekBar hueSeekBar; 
    private SeekBar satSeekBar; 
    private SeekBar briSeekBar; 

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

     light = (LightBulb) getIntent(). 
       getSerializableExtra("LIGHTBULB"); 
     label = (TextView) findViewById(R.id.labelTextView); 
     label.setText(light.getDescr()); 

     hueSeekBar = (SeekBar) findViewById(R.id.hueSeekBar); 
     hueSeekBar.setProgress(light.getHue()); 
     hueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
      @Override 
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {} 

      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {} 

      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) { 
       light.setHue(hueSeekBar.getProgress()); 
      } 
     }); 

     satSeekBar = (SeekBar) findViewById(R.id.satSeekBar); 
     satSeekBar.setProgress(light.getSat()); 
     satSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
      @Override 
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {} 

      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {} 

      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) { 
       light.setSat(satSeekBar.getProgress()); 
      } 
     }); 

     briSeekBar = (SeekBar) findViewById(R.id.briSeekBar); 
     briSeekBar.setProgress(light.getBri()); 
     briSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
      @Override 
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {} 

      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {} 

      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) { 
       light.setBri(briSeekBar.getProgress()); 
      } 
     }); 
    } 
} 

マイlight_details XMLファイル:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="16dp" 
    android:paddingLeft="64dp" 
    android:paddingRight="64dp" 
    android:paddingTop="16dp" 
    tools:context="nl.mirjamvanmourik.hueemulator.LightBulbDetails"> 

    <TextView 
     android:id="@+id/labelTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="30dp" /> 

    <TextView 
     android:id="@+id/hueTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hue: " /> 

    <SeekBar 
     android:id="@+id/hueSeekBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:max="65535" /> 

    <TextView 
     android:id="@+id/satTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Saturation: " /> 

    <SeekBar 
     android:id="@+id/satSeekBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:max="254" /> 

    <TextView 
     android:id="@+id/briTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Brightness: " /> 

    <SeekBar 
     android:id="@+id/briSeekBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:max="254" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Pas aan" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Annuleer" /> 

    </LinearLayout> 

</LinearLayout> 

私はすでに私のマニフェストに活動を追加しました。

ありがとうございます!

+0

ようLightBulbDetailsから取得することができ、あなたは間違いなく、問題を見つけることは非常に重要であるクラッシュレポートを取得します。あなたのlogcat(Androidモニター)のフィルタを削除するだけで、あなたが表示されます。 – Opiatefuchs

+0

シンプルな問題は、マニフェスト内にあなたのアクティビティを登録していない可能性があります。 – Opiatefuchs

+0

私はAndroidモニターで解決策を見つけましたが、それを完全に忘れました!ありがとう:)私はBridgeでもSerealizableを実装する必要があることが判明しました –

答えて

1

私はあなたの電球のクラスは、例えばシリアライズ

を実装する必要があります

class LightBulb implements Serealizable 
+0

可能です... – Opiatefuchs

+0

LightBulbのために使用しましたが、私はBridgeでもLightBulbを使用する必要があると考えました。ご支援ありがとうございます! –

+0

実際にLightBulbとBridgeのためにあなたから提供された構造体はありません。そのためLightBulbのみを提案しました。なぜなら、私はそのクラスのリファレンスを見ることができるからです。 :) –

0

以下のようにあなたは がSerealizableであなたの電球のクラスを実装していることを確認し、Serealizableを使用していないと思います

class LightBulb implements Serealizable{ 
    // Your Implementation 
} 

次に、LightBulbオブジェクトを余分に配置することができます。

LightBulb light = (LightBulb) list.get(position); 
Intent intent = new Intent(getApplicationContext(), LightBulbDetails.class); 
intent.putExtra("LIGHTBULB", light); 
startActivity(intent); 

そして、あなたはアプリのcrashs場合に

light = (LightBulb) getIntent().getSerializableExtra("LIGHTBULB"); 
関連する問題