2017년 8월 23일 수요일

Error occur when running the app


Recently I am reading the article  Build a Personal Safety Application in App Inventor 2

It told me about how to make a self protect button which can send text and phone call to someone when in danger.
I follow the exact instruction there and  I run the program and save my text.But when I press Help button, the app said "Run time error , attempt to get length of null array"
I also found that the link above can use the same TinyDB(TinyDB1) and notifier(notifier1) between two screens, how he did that? 
I really want to make this function so please help me.

--
If you want help, you should provide more information.
Please attach a screenshot of your blocks!

The information in a TinyDB is shared between all screens, you just have to define it in every screen you are using it,
A notifier is not really shared, it just happens to have the same name.

--
I am suvarna. I am making app for multiple sensor data display on app. I have a made two screen in my app. In my app  Bluetooth is connected on first screen and sensor data receive on second screen.I have trouble in receiving data on second screen. would you please explain me how can i receive data on second screen. which component is used for data receiving on second screen from bluetooth. 
please reply as soon as possible.
waiting for your positive reply.

--
Now I first change back to one screen and try again but the Error message "Attempt to get length of null array" still present so I guess screen is not the problem.
Here is my block, please help me check for the error , thanks!



--
Could you please open a new thread for your question about a very different subject? I will tell you there that you can only use Bluetooth from Screen1.

--
Your logic is probably not what you want:

if TextContact is empty then show notifier
  else (TextContact is not empty)
       if Callcontact is empty then show notifier
          else (both text and call conact are not empty!)
              if both are empty (this cannot happen here!)

In short it is possible that there are empty fields when you store the values.
What you can do is, to simplify this:

if not is empty TextContact AND not is empty CallContact
  then store the values in the TinyDB
  else show notifier: both fields must be filled

--
Thank you so much. I solved the problem

--
Did you notice that you were using different TinyDB tags to store and retrieve the same data?

--

Rectangle extension.


I just wonder, is it possible to create a rectangle extension in AI2?  Can one modify the ball.java file, and based on that create a rectangle instead?
Is this a complicated thing to do?

From the ball.java code:

protected void onDraw(Canvas canvas) {
    if (visible) {
      float correctedXLeft = (float)(xLeft * form.deviceDensity());
      float correctedYTop =  (float)(yTop * form.deviceDensity());
      float correctedRadius = radius * form.deviceDensity();
      canvas.drawCircle(correctedXLeft + correctedRadius, correctedYTop +
          correctedRadius, correctedRadius, paint);
    }
  }

Is there any kind of canvas.drawRectangle?

--
Next time search the gallery:



--
So I know I haven't explained exactly what I want.  To create a function like this is no probelm (that I've already done)

But I want to add events to my rectangle.  For the ball component you have:

When ball1 collide with

When ball1 dragged
When  ball1 edge reached
when ball1 flung
when ball1 toucdown

and so on.  I don't think thats possible with this solution?

--
A ball is really a sprite, so, you can make a sprite with the image of a rectangle, give it any width and height you need, since pixelation or distortion doesn't matter in this case and that's it. You have a "rectangular ball"!

--
But isn't your rectangle just a Sprite with a very boring rectangular image?

--
Sure, one can use an image of a rectangle.  So if one would change the colour of this rectangle, you have to add a new image.  
Ok, thats a workable solution, but not the most elegant......

--
You can draw a rectangle of any color possible, save the canvas as a file, then use that file as the sprite picture.

--
Not sure how to save a canvas..... BUT: I have created 2 images (png) with size 100X100 px.  And I am able to change picture and then colour of the rectnagle!!
If I change height  or wdith of the imagesprite it will work as long as it is less than 100X100px.  Thanks for your adivse,  I guess this is much easier than creating an extension:)

--