我正在为我的三星 Note 3.0 制作一个示例 Spen SDK 应用程序,并且正在使用 Android Studio。相关的xml文件是: -
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/settingBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="pen"
android:layout_weight="1"/>
<Button
android:id="@+id/eraseBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="erase"
android:layout_weight="1"/>
<Button
android:id="@+id/undoBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="undo"
android:layout_weight="1"/>
<Button
android:id="@+id/redoBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="redo"
android:layout_weight="1"/>
</LinearLayout>
<FrameLayout
android:id="@+id/canvas_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.samsung.sdraw.CanvasView
android:id="@+id/canvas_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
/>
<com.samsung.sdraw.SettingView
android:id="@+id/setting_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
对应的java代码是:-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity mContext = this;
CanvasView mCanvasView = (CanvasView) findViewById(R.id.canvas_view);
RelativeLayout mCanvasContainer = (RelativeLayout) findViewById(R.id.canvas_container);
SCanvasView mSCanvas = new SCanvasView(mContext);
mCanvasContainer.addView(mSCanvas);
}
现在,当我尝试通过将三星 Note 3.0 连接到 PC 来调试应用程序时,应用程序启动,显示主页面并在一秒钟内崩溃。我在网上搜索并找到了this和this。我的 libs 文件夹中也没有Spen SDK 的armeabi目录。所以,我包含了这些库,现在我的项目的 libs 文件夹看起来像:-
libs <-- my Project's folder
libs
armeabi
libspen23.jar
libspen23_multiwindow.jar
但同样的事情仍在发生。没有编译错误。然后我注意到的一件事是我的 xml 文件无法由 Android Studio 呈现。以下是截图:
例外情况是:-无法实例化以下类:
- com.samsung.sdraw.CanvasView(渲染期间不允许写访问(\mnt\sdcard\android\data\null\serial))
- com.samsung.sdraw.SettingView(java.lang.NullPointerException )
谁能告诉我问题是什么?
更新:
我已经调试了应用程序,异常发生在
setContentView(R.layout.activity_main);
在 OnCreate() 中。但我不知道为什么应用程序在那里崩溃。
- gradle 文件是:-
apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion '19.1.0' defaultConfig { applicationId 'com.example.myapplication3.app' minSdkVersion 9 targetSdkVersion 19 versionCode 1 versionName '1.0' } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile files('libs/libspen23.jar') compile 'com.android.support:appcompat-v7:19.+' compile files('libs/libs/libspen23.jar') }
- 如果我注释 xml 文件中的 CanvasView 和 SettingsView 块以及 OnCreate() 函数中的相应行,应用程序就会运行。