Android无法启动活动android.view.inflate异常。应用程序崩溃在`setContentView()`上

时间:2014-05-06 07:56:08

标签: java android

我已经开始使用android编程了。这些应用程序启动崩溃让我疯狂。目前我在eclipse中有一个Android应用程序和一个Android库项目。我正在跟踪logcat中的错误

logcat的

01-22 06:00:33.167: E/AndroidRuntime(25666): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.camerafilters/com.example.camerafilters.CameraMainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class org.lucasr.twowayview.TwoWayView
01-22 06:00:33.167: E/AndroidRuntime(25666):    at com.example.camerafilters.CameraMainActivity.onCreate(CameraMainActivity.java:44)`

图书馆是TwoWayView。这是我的activity_main.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<com.example.camerafilters.CameraGLSurfaceView
    android:id="@+id/CameraGLSurfaceView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="8"/>

<org.lucasr.twowayview.TwoWayView
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ShaderList"
    style="@style/TwoWayView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:drawSelectorOnTop="false"
    tools:context=".CameraMainActivity"  />

</LinearLayout>

这是我的onCreate()功能

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

    //_cameraGLView = new CameraGLSurfaceView(this, null);
    // Create a GLSurfaceView instance and set it
    // as the ContentView for this Activity. 
    setContentView(R.layout.activity_main);

    _cameraGLView = (CameraGLSurfaceView) findViewById(R.id.CameraGLSurfaceView);
    _renderer = _cameraGLView.getRenderer();

    _renderer.setPreviewDimensions(_cameraGLView.getWidth(), _cameraGLView.getHeight());

    // now setup list view of shader
    _setupShaderListView();
}

如果需要更多代码,请告诉我。应用程序在setContentView()函数中崩溃。我在同一工作区中还有一个项目使用相同的配置。该项目还使用了一个GLSurfaceViewTwoWayView列表,该项目工作正常。

这里是stacktrace

CameraFilters [Android Application] 
DalvikVM[localhost:8617]    
    Thread [<1> main] (Suspended (exception RuntimeException))  
        <VM does not provide monitor information>   
        ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2308    
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2362 
        ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 168    
        ActivityThread$H.handleMessage(Message) line: 1329  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 177 
        ActivityThread.main(String[]) line: 5493    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 525  
        ZygoteInit$MethodAndArgsCaller.run() line: 1225 
        ZygoteInit.main(String[]) line: 1041    
        NativeStart.main(String[]) line: not available [native method]  
    Thread [<10> Binder_2] (Running)    
    Thread [<9> Binder_1] (Running) 
    Thread [<11> GLThread 22597] (Running)  

更新
所以我做了一些调试,发现两个项目都在不同的驱动器中。这有什么不同吗?成功运行的项目位于TwoWayView的同一驱动器中。虽然这个项目是在eclipse工作区和不同的驱动器然后双向视图。

更新2
我把库移到了同一个目录但仍然没有运气。即使是现在正在工作的那个:(。这两个项目之间的更多调查和合作正在给出一些指示。虽然我已经完成了相同的配置,但我可以在TwoWayView库部分中看到这个Project Properties->Android就像在这个项目中一样,我不能。当我从那里删除这个库时,以前的项目也开始崩溃了。

1 个答案:

答案 0 :(得分:-1)

更改为:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<com.example.camerafilters.CameraGLSurfaceView
    android:id="@+id/CameraGLSurfaceView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="8"/>

<org.lucasr.twowayview.TwoWayView

    android:id="@+id/ShaderList"
    style="@style/TwoWayView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:drawSelectorOnTop="false"
    tools:context=".CameraMainActivity"  />

</LinearLayout>

并发布完整堆栈跟踪。

相关问题