Error from getWindowManager in DisplayMetrics declaration error in Android

时间:2017-08-30 20:20:34

标签: java android android-windowmanager

I'm designing my first android app, and part of that requires getting the screen size. I'm using the .bashrcobject in the standard way:

totalcol = [0,0,0,0] #Store sum results in a list
with open('myfilename','r') as f:
for line in f
    #split line and keep columns 9,10,11,12
    #assuming you are counting from 1 and have only 12 columns
    datacol = line.rstrip("\n").split("\t")[8:]  #lists start at index 0!
    #Loop through each column and sum the 3rd element
    for i,element in enumerate(datacol):
        splitcol=int(element.split(":")[2])
        totalcol[i] += splitcol
print(totalcol)

But I am getting an Invalid method declaration error on the 2nd line, on each of the 3 methods. This code is in my mainactivity.java file, created as an empty activity. None of the alterations suggested in other questions help here. I have tried the (Activity) cast and getContext() methods.

This is the whole file:

<body>

<header> </header>

<div class="scroll-vertical" id="tile1"></div>
<div class="scroll-vertical" id="tile2"></div>
<div class="scroll-vertical" id="tile3"></div>

<div class="scroll-horizontal" id="tile4">
    <div class="horizontal" id="tile5"></div>
    <div class="horizontal" id="tile5-a"></div>
    <div class="horizontal" id="tile5-b"></div>
    <div class="horizontal" id="tile5-c"></div>
</div>

<div class="scroll-vertical" id="tile6"></div>
<div class="scroll-vertical" id="tile7"></div>
<footer> </footer>

Any pointers greatly appreciated.

1 个答案:

答案 0 :(得分:2)

You should just use this code inside onCreate method and not outside. Remove unnecessary braces and its all good.

def calculate_gradient_magnitude(dcm):
    print "calculating gradient magnitude"
    gradient_magnitude = []
    gradient_direction = []

    gradx = np.zeros(dcm.shape)
    sobel(dcm,0,gradx)
    grady = np.zeros(dcm.shape)
    sobel(dcm,1,grady)
    gradz = np.zeros(dcm.shape)
    sobel(dcm,2,gradz)

    gradient = np.sqrt(gradx**2 + grady**2 + gradz**2)

    azimuthal = np.arctan2(grady, gradx)
    elevation = np.arctan(gradz,gradient)

    azimuthal = np.degrees(azimuthal)
    elevation = np.degrees(elevation)

    return gradient, azimuthal, elevation