2013-02-19 56 views
0

进出口新到Java在很多方面和我的生活不能弄清楚,为什么我的“imageactivity”布局,则无法在运行时被发现时,其在编译时发现的。该文件位于“penguinplugin /苏亚雷斯/布局/ imageactivity.xml” ......是不是我需要在Eclipse或我的清单来设置被发现呢?的setContentView抛出错误的NoClassDefFoundError

注:如果我提取我的建.jar文件,它不包含“R $ layout.class”。这是一个图书馆BTW,不激动...

我的布局XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/imageactivityID" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <SurfaceView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.86" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:text="Take Picture!" /> 

</LinearLayout> 

我的活动:

import com.penguin.penguinplugin.R; 
public class PhotoPickerActivity extends Activity implements OnClickListener 
{ 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.imageactivity); 
    } 
} 

抛出的异常:

E/AndroidRuntime(1285): FATAL EXCEPTION: main 
E/AndroidRuntime(1285): java.lang.NoClassDefFoundError: com.penguin.penguinplugin.R$layout 
E/AndroidRuntime(1285): at penguinplugin.PhotoPickerActivity.onCreate(PhotoPickerActivity.java:47) 
E/AndroidRuntime(1285): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
E/AndroidRuntime(1285): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1617) 
E/AndroidRuntime(1285): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1669) 
E/AndroidRuntime(1285): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
E/AndroidRuntime(1285): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:937) 
E/AndroidRuntime(1285): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime(1285): at android.os.Looper.loop(Looper.java:130) 
E/AndroidRuntime(1285): at android.app.ActivityThread.main(ActivityThread.java:3692) 
E/AndroidRuntime(1285): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(1285): at java.lang.reflect.Method.invoke(Method.java:507) 
E/AndroidRuntime(1285): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 
E/AndroidRuntime(1285): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
E/AndroidRuntime(1285): at dalvik.system.NativeStart.main(Native Method) 

编辑:所以我认为它可能不工作的原因是因为Eclipse不会ILT资源到库对象(如果有的话,手掌)...只有一个exe。但由于这是一个统一的插件,我只是编程的方式创建,我需要不加载任何资源的简单视图。所以我的问题就解决了。

回答

2

你需要一个单一的父对象添加到您的布局文件

这样的事情应该做的:

<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" 
    tools:context=".YourActivity" > 

    <SurfaceView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.86" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:text="Take Picture!" /> 
</LinearLayout> 
+0

Sry基因更新了我的XML文件,并没有意识到整个代码块不显示在我的文章正确。因此,从看您的文章,它看起来像我缺少一个“语境”?这可能是我的问题吗?我应该删除XML标题标签吗? – zezba9000 2013-02-20 00:26:07