2016-07-07 347 views
0

我收到錯誤:「在我的代碼中無法解析方法'super()'」,我不知道如何解決此問題,是否有任何線索?無法解析android studio中的方法'super()'錯誤

的代碼如下:

public GeoView(double left, double top, double width) 
{ 
    super(); 

    this.left = left; 
    this.top = top; 
    this.width = width; 

    this.transform = null; 
    this.backing_store = null; 

    this.sink = false; 

    this.last_size = new Rect(0, 0, 200, 200); 
    this.do_tracking = false; 

    Drawable background = new Drawable() { 
     @Override 
     public void draw(Canvas canvas) { 

     } 

     @Override 
     public void setAlpha(int i) { 

     } 

     @Override 
     public void setColorFilter(ColorFilter colorFilter) { 

     } 

     @Override 
     public int getOpacity() { 
      return 0; 
     } 
    }; 
+2

請顯示封閉類。 – kalabalik

+0

請分享封閉班級的詳細信息,以瞭解班級出席 – Kushan

+0

顯示繼承請求,否則我們不能幫助您。 –

回答

0

什麼是GeoView類?你從另一個課程擴展它? 如果是。檢查父類是否有空的構造函數,因爲你調用它。
如果這是你自己的班級,並沒有從任何其他班級延伸。那麼你不需要撥打super()

查看沒有空構造函數。 你應該有這個構造函數的列表之一。

public GeoView(Context context) { 
     super(context); 
    } 

    public GeoView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public GeoView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

如果你想自己創建視圖,你需要第一個構造函數。那麼你必須

GeoView geoView = new GeoView(YourActivity.this); 

或者你可以簡單地驢視圖佈局。然後你第二個將被稱爲構造函數。我認爲你應該添加所有這些。

<com.example.yourapp.GeoView 
    android:layout_height="300dp" 
    android:layout_width="match_parent"/> 
+0

它從類視圖擴展。 – JackD

+0

謝謝你,它的工作!我有一個擴展GeoView的類MapViewer,我修改了構造函數以包含上下文,但是,當我創建MapViewer對象時,如何或在哪裏創建Context對象?是否可以輸入:Context contextObj = new Context();並將contextObj傳遞給MapViewer調用? – JackD

+0

否上下文是您的活動。新的地理地圖(YourActivity.this); – thealeksandr

相關問題