0

I am making a sample Spen SDK app for my Samsung Note 3.0 and am using Android Studio. The relavant xml file is:-

<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>

And the corresponding java code is:-

 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);
    }

Now when I try to debug the app by connecting Samsung Note 3.0 to PC, the app launches, shows the mainPage and crashes within a second. I searched on the net and found this and this. I too didn't have armeabi directory of Spen SDK in the libs folder. So, I included the libraries and now my project's libs folder looks like:-

libs <-- my Project's folder
  libs
    armeabi
    libspen23.jar
    libspen23_multiwindow.jar

But still the same thing is happening. There is no compile error. One thing that I then noticed was that my xml file could not be rendered by the Android Studio. Following is the screenshot: enter image description here

The exeptions are:- The following classes could not be instantiated:

  • com.samsung.sdraw.CanvasView (Write access not allowed during rendering(\mnt\sdcard\android\data\null\serial) )
  • com.samsung.sdraw.SettingView(java.lang.NullPointerException )

Can anyone tell me what thw problem is?

UPDATE:

  1. I have debugged the app and exception occurs at

    setContentView(R.layout.activity_main);

in OnCreate(). But I can't find out why is the app crashing there.

  1. The gradle file is:-
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')  
}
  1. The app runs if I comment the CanvasView and SettingsView blocks from xml file and the corresponding lines from OnCreate() function.
Community
  • 1
  • 1
AvinashK
  • 3,309
  • 8
  • 43
  • 94
  • You should use logcat rather than the breakpoint to examine this type of problem, and edit the resulting **stack trace** of the crash into your question. But chances are your activity_main xml is either invalid or contains a reference to a custom component which is not getting onto the device. – Chris Stratton Jul 27 '14 at 22:18

1 Answers1

-1

When you are using layount-weight you should set either layout-width or layout-height to 0dip. Try setting android:layout_width="0dip" in each button. Maybe that will do it. If not try commenting this:

<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" />

If it helps we will know where the problem is.

Also please paste your build.gradle

marcinm
  • 281
  • 1
  • 2
  • 11
  • @marcinm...Commenting the CanvasView and SettingView blocks made the application run withour crash. There were 4 buttons which were visible in the homescreen of the app. – AvinashK Jun 09 '14 at 10:59
  • Okay I will tell you what I do in my project maybe it will help. Move your .jars to top level(same as build.gradle) libs dir. Change in gradle.build -> compile files('libs/libspen23.jar') compile files('libs/libspen23_multiwindow.jar'). Than create in folder main subfolder jniLibs and paste there armeabi with its content. It works for me, beacuse Android Studio automatically adds native libs from jniLibs folder to the project. – marcinm Jun 09 '14 at 11:24