2014-12-28 4 views
0

를 반환합니다. 하지만 현재의 문제는 훨씬 더 혼란 스럽습니다. 실제 카메라 사진을 보여주기 위해 CustomPreviewClass를 만들었습니다. 하지만 불행히도, 뷰에 액세스하려고하면 findViewById() 메서드는 항상 null을 반환합니다. 왜? 아무도 아이디어가 있니?안드로이드 findViewById를 항상 내가 안드로이드 NDK 및 Live555를 사용하여 스트리밍 응용 프로그램을 구축을 위해 노력하고, 현재는 null

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

    preview = (CameraPreview) findViewById(R.id.surfaceView1); // returns null 
    if (preview == null) Log.d("Test", "Preview is null"); 

    final Button buttonStart = (Button) findViewById(R.id.buttonStart); 
    buttonStart.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      try { 
       startRecording(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      buttonStart.setEnabled(false); 
     } 
    }); 

    final Button buttonStop = (Button) findViewById(R.id.buttonStop); 
    buttonStop.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      stopRecording(); 
      buttonStart.setEnabled(true); 
     } 
    }); 
} 

그냥 보조 노트 : 여기

내 활동의 잘 작동 버튼의 findViewById를() ...

activity_main.xml :

<FrameLayout 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" 
tools:context="de.douglasmedia.LiveCam.MainActivity" > 

<de.douglasmedia.LiveCam.views.CameraPreview 
    android:id="@+id/surfaceView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</de.douglasmedia.LiveCam.views.CameraPreview> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/buttonStart" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Start" > 
    </Button> 

    <Button 
     android:id="@+id/buttonStop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Stop" > 
    </Button> 
</LinearLayout> 

CameraPreview :

당신의 도움에 대한
... 
public CameraPreview(Context context, AttributeSet attrs) { 
    this(context); 
} 

public CameraPreview(Context context) { 
    super(context); 
    SurfaceHolder holder = getHolder(); 
    holder.addCallback(this); 
} 

@Override 
public void surfaceCreated(SurfaceHolder holder) { 
    synchronized (surfaceCreationSync) { 
     surfaceCreatedHolder = holder; 
     surfaceCreationSync.notifyAll(); 
    } 
} 
... 

감사합니다!

답변

0

나는 내 자신이 문제를 해결했습니다. 문제는 CameraPreview 클래스에서 3 가지 인수로 생성자를 놓쳤다는 것입니다. 그래서,이 생성자를 추가하고 모든 ...

잘 작동