2014-07-17 141 views
1

您能否告訴我如何正確覆蓋「createViews」?如果我在它之前放置@Override,它會說:「WhatSnap類型的createViews()方法必須覆蓋或實現超類型方法」 如果我刪除@Override,它不會被執行。 這是第一類:https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaActivity.java#L267如何覆蓋函數?

這是第二個在至極我要重寫createViews:

package com.Snap.What; 

import android.graphics.Color; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Display; 
import android.view.View; 
import android.widget.RelativeLayout; 

import org.apache.cordova.*; 

import com.startapp.android.publish.StartAppAd; 
import com.startapp.android.publish.StartAppSDK; 
import com.startapp.android.publish.banner.Banner; 

public class WhatSnap extends CordovaActivity 
{ 
    private CordovaWebView cordova_webview; 
    private StartAppAd startAppAd = new StartAppAd(this); 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     super.init(); 
     // Set by <content src="index.html" /> in config.xml 
     super.loadUrl(Config.getStartUrl()); 
     //super.loadUrl("file:///android_asset/www/index.html"); 
     StartAppSDK.init(this, "xxx", "xxx", true); 
     Log.e("activity", "activity"); 
    } 

    @Override 
    protected void createViews(){ 
     RelativeLayout layout = new RelativeLayout(this); 

     RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
      RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT); 
     layout.setLayoutParams(lp); 

     appView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); 
     Log.e("createViews", "createViews"); 
       appView.setVisibility(View.INVISIBLE); 
      layout.addView((View) appView); 
      setContentView(layout); 

      Banner startAppBanner = new Banner(this); 
      RelativeLayout.LayoutParams bannerParameters = 
         new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, 
            RelativeLayout.LayoutParams.WRAP_CONTENT); 
      bannerParameters.addRule(RelativeLayout.CENTER_HORIZONTAL); 
      bannerParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);  
      // Add to main Layout 
      layout.addView(startAppBanner, bannerParameters); 
    } 


    @Override 
    protected CordovaWebView makeWebView(){ 
     Log.e("CordovaWebView", "CordovaWebView"); 
     return new CordovaWebView(WhatSnap.this); 
    } 




} 
+0

的createViews的簽名只是更改爲保護.. –

+0

@ l0oky我試過的人,它不工作。我得到同樣的錯誤! –

回答

1

您必須使用相同的訪問修飾符作爲超類的方法。更改覆蓋簽名,

@Override 
protected void createViews(){ 
    //Your code here 
} 
+0

我試過那個男人,它不工作..我得到同樣的錯誤! –

+0

您是否也更改了makeWebView()的簽名?你也錯誤地忽略了這一點。 – gnuanu

+0

我改變了ti,但我仍然得到錯誤ar覆蓋線上方creatViews() –