0

I developed a android homescreen, the code seems right but when I run the project I get the following error:

java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{com.matthieu.launcher/
com.matthieu.launcher.DragableSpace}:
java.lang.InstantiationException: com.matthieu.launcher.DragableSpace

Here is the complete log: http://pastebin.com/iYtYW2W6

The code is straight from the Android Launcher.

DragableSpace: http://pastebin.com/jpWDtFPF

MainActivity:

public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DragableSpace space = new DragableSpace(this.getApplicationContext());
        setContentView(space);
    }
}

attr.xml in values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="DragableSpace">
        <attr name="default_screen" format="integer"/>
    </declare-styleable>
</resources>

Three xml files initial_screen, left_screen and right_screen, all have same code apart from the id:

<LinearLayout android:id="@+id/center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">
</LinearLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.matthieu.launcher"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

Any ideas how to fix that?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • Your pastebin post of your stack trace isn't the full stack trace, i.e. it has the line 12-26 10:59:42.537: ERROR/AndroidRuntime(4220): ... 11 more.. which means some stack information is missin, If your able to put up the full stack trace it might allow someone to fuller understand where the error is occurring. – Emile Jan 03 '11 at 15:16
  • I do not know how to reveal the 11 more, I added the text view like described by John smith in his answer and from 16:06 I get an other error, http://pastebin.com/LHfbHsvm – DarkLeafyGreen Jan 03 '11 at 15:24
  • Put a break point in just before line 170 of your DraggableSpace and step through in debug mode. You'll need to see what value is null and work back to determine why its null. Sorry i can't be of more help. – Emile Jan 03 '11 at 15:32
  • this is my log now http://pastebin.com/BPQtLUsK I have no errors but it does not work, It does not snap screens, log shows always snap to screen 0 – DarkLeafyGreen Jan 03 '11 at 15:42

3 Answers3

1

Had a quick look at the code as it is now. NullPointerException at line 169 of DragableSpace, due to no child view - fix this by adding a child view in the MainActivity:

TextView child = new TextView(this);        
    child.setText("This is a Test");
    space.addView(child);

So now the code runs and logs the touch events to LogCat but nothing appears to happen (I'm guessing you want 3 spaces which can be dragged and repositioned on the screen) - some initial problems, I think, the SNAP_VELOCITY value of 1000 seems a bit high to me for some dragging gestures, none of the layout xml files appear to be used, and if the current 'screen' is the full width and height of the device, where does it get dragged to?

Updated: Add the previous post's xml layout as the main.xml:

<?xml version="1.0" encoding="utf-8"?>

Now, in the MainActivity, set the content as:

setContentView(R.layout.main);

Also, to make it easier to see what's happening, I set the background colours to different colours - add the following colours to the strings.xml file:

<color name="green">#21d081</color>
<color name="blue">#00A0FF</color>
<color name="orange">#EA6700</color>

And edit the screen xml files to add a colour e.g. in the left_screen.xml file, add the following attribute:

android:background="@color/blue"

And use a different colour for the initial_screen.xml and the right_screen.xml and when you run the project, you can drag across the screen and reveal a new area.

alt text

John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • My first version was completly different from this version of the android homescreen so I am not really sure what to fix. Have a look at a earlier post http://stackoverflow.com/questions/3467461/developing-an-android-homescreen the version seems to work for some poeple but I do not know why – DarkLeafyGreen Jan 03 '11 at 14:58
  • I tried adding the textview, the app does not crash anymore but the flipping does not work – DarkLeafyGreen Jan 03 '11 at 15:10
  • Ok, now I understand - and it works ok now. Add the layout xml which was identified in the earlier post as the layout main.xml and use this to set the content in the activity - I've edited my earlier answer. – John J Smith Jan 04 '11 at 01:09
1

On a side note, and this is more of an observation, in your DragableSpace code i've noticed two things.

  1. In public DragableSpace(Context context, AttributeSet attrs) {... you haven't called a.recycle(); after you've accessed all your properties of obtainStyledAttributes. This is bad i think.

  2. I'm not entirely sure, as i've just picked up java, but i found that i had to change super.DragableSpace(...) to this.DragableSpace(...). This could have just been particular to my component, but wasn't entirely sure if that was correct or not.

Emile
  • 11,451
  • 5
  • 50
  • 63
0

DragableSpace is a ViewGroup. DragableSpace is not an Activity. Home screens are activities. Hence, DragableSpace cannot be a home screen.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491