在视图中输入类时出错

时间:2015-07-27 16:54:41

标签: java android xml android-inflate

我已经看过问题建议,但我找不到答案。

LogCat会抛出此错误:

I/Timeline( 7748): Timeline: Activity_launch_request id:com.miracle.livapp time:45951871
I/ActivityManager(  768): START u0 {flg=0x10000000 cmp=com.miracle.livapp/com.odizzain.cordova.plugins.livestream.CameraStreamingActivity} from uid 10252 on display 0
E/AndroidRuntime( 7748): Process: com.miracle.livapp, PID: 7748
E/AndroidRuntime( 7748): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.miracle.livapp/com.odizzain.cordova.plugins.livestream.CameraStreamingActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class ru.denivip.nine00secondssdk.hlsstreaming.Nine00SecondsCameraView
D/ActivityManager(  768): New dropbox entry: com.miracle.livapp, data_app_crash, 877fda44-aca7-4a69-8c23-c0da45fa7bd4
W/ActivityManager(  768):   Force finishing activity com.miracle.livapp/com.odizzain.cordova.plugins.livestream.CameraStreamingActivity
W/ActivityManager(  768):   Force finishing activity com.miracle.livapp/.MainActivity
W/ActivityManager(  768): Activity pause timeout for ActivityRecord{3e7cfd61 u0 com.miracle.livapp/com.odizzain.cordova.plugins.livestream.CameraStreamingActivity t82 f}
W/ActivityManager(  768): Activity destroy timeout for ActivityRecord{338f1497 u0 com.miracle.livapp/.MainActivity t82 f}
W/ActivityManager(  768): Activity destroy timeout for ActivityRecord{3e7cfd61 u0 com.miracle.livapp/com.odizzain.cordova.plugins.livestream.CameraStreamingActivity t82 f}

所涉及的类有两个构造函数,避免了我在其他地方读到的第二个参数问题:

public Nine00SecondsCameraView(Context context){
    super(context, null);
}

public Nine00SecondsCameraView(Context context, AttributeSet attrs) {
    super(context, attrs);
    ....
}

这是XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ru.denivip.nine00secondssdk.hlsstreaming.Nine00SecondsCameraView
    android:id="@+id/streamingView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<ImageButton
    android:id="@+id/toggleRecording_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="16dp"
    android:background="@drawable/circle_button_background_selector"
    android:src="@drawable/reccord_button"
    android:clickable="true"
    android:onClick="clickToggleRecording" />
</RelativeLayout>

这是CameraStreamingActivity.java

package com.odizzain.cordova.plugins.livestream;


import ru.denivip.nine00secondssdk.hlsstreaming.Nine00SecondsCameraView;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class CameraStreamingActivity extends Activity {


    private String appPackageName = null;
    private Resources appResources = null;

    private Nine00SecondsCameraView streamingView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        appPackageName = getApplication().getPackageName();
        appResources = getApplication().getResources();
        // appResources.getIdentifier("activity_camerabroadcast", "layout", appPackageName)

        setContentView(appResources.getIdentifier("camera_streaming_activity", "layout", appPackageName));
        streamingView = (Nine00SecondsCameraView) findViewById(appResources.getIdentifier("streamingView", "id", appPackageName));
    }

    @Override
    protected void onResume() {
        super.onResume();
        streamingView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        streamingView.onPause();
    }

    /**
     * onClick handler for "record" button.
     */
    public void clickToggleRecording(View unused) {
        if (streamingView.isRecording())
            streamingView.stopRecording();
        else
            streamingView.startRecording();

        updateControls();
    }


    /**
     * Updates the on-screen controls to reflect the current state of the app.
     */
    private void updateControls() {
        ImageButton toggleRelease = (ImageButton) findViewById(appResources.getIdentifier("toggleRecording_button", "id", appPackageName));

        int id = streamingView.isRecording() ?
                appResources.getIdentifier("stop_reccord_button", "drawable", appPackageName) :
                appResources.getIdentifier("reccord_button", "drawable", appPackageName);

        toggleRelease.setImageResource(id);
    }

}
不过,我正在使用这个sdk:http://livestreamsdk.com/

1 个答案:

答案 0 :(得分:0)

我解决了为这三个和四个参数添加构造函数的问题:

SurfaceView(Context context, AttributeSet attrs, int defStyleAttr)
SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

就像android documentation所说的那样。