Hello I want to make an application which uses Multi-touch support.
for multitouch i am using this code
Now in that you can see that there is org.metalev.multitouch.photosortr.PhotoSortrActivity Activity
in that the code is like below
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle(R.string.instructions);
photoSorter = new PhotoSortrView(this);
setContentView(photoSorter);
}
it will work fine
but instead of this if i want to add this view in my view i write above code like below…
i have make one XML file named activity_main.xml
<org.metalev.multitouch.photosortr.PhotoSortrView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</org.metalev.multitouch.photosortr.PhotoSortrView>
and in onCreate method i have change like below
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle(R.string.instructions);
photoSorter = new PhotoSortrView(this);
setContentView(R.layout.activity_main);
}
if i do like this way i will get an error below is logcat
10-30 12:15:29.319: E/AndroidRuntime(6652): java.lang.NullPointerException
10-30 12:15:29.319: E/AndroidRuntime(6652): at org.metalev.multitouch.photosortr.PhotoSortrView$Img.draw(PhotoSortrView.java:274)
10-30 12:15:29.319: E/AndroidRuntime(6652): at org.metalev.multitouch.photosortr.PhotoSortrView.onDraw(PhotoSortrView.java:86)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.View.draw(View.java:6914)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.View.draw(View.java:6917)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.widget.FrameLayout.draw(FrameLayout.java:357)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
10-30 12:15:29.319: E/AndroidRuntime(6652): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
in PhotoSortrView.java file the code is like below where i m getting this error
public void draw(Canvas canvas) {
canvas.save();
float dx = (maxX + minX) / 2;
float dy = (maxY + minY) / 2;
---->drawable.setBounds((int) minX, (int) minY, (int) maxX, (int) maxY); // HERE getting drawable == NULL
canvas.translate(dx, dy);
canvas.rotate(angle * 180.0f / (float) Math.PI);
canvas.translate(-dx, -dy);
drawable.draw(canvas);
canvas.restore();
}
Only cause might be that
drawableused indraw()ofImgclass is null, sincecanvasis passed by system, and rest variables in method are primitives. This variable is initialized inload()ofImgclass , which in turn is called fromloadImages()ofPhotoSortrViewclass.Now, I guess you are calling
loadImages()ofphotoSortervariable from Activity’sonResume(). But there is anotherPhotoSortrViewinstance created from inflating the layout. Make sure you callloadImages()of that instance also.