Android:无法从内部类启动新的Activity

时间:2013-04-06 04:18:41

标签: android android-intent android-activity

Android:有人帮忙: 我注意到其他人之前已经问过这种问题,但答案对我的情况没有用处;我需要从内部发起一个新的活动 但我得到的只是下面的错误:

04-05 15:00:43.851: E/AndroidRuntime(3288): Caused by: java.lang.InstantiationException: com.school.School$StudentProfile

这是我的代码段:

public class School extends Activity{
ProgressDialogue progressDialogue;

protected WebViewTask _webTask;

String path = "http://www.school.com/student/"; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.school);


    progressDialogue = new ProgressDialogue(School.this);

    _webTask = new WebViewTask();
    _webTask.execute();

}   

//rest of the code

  /** The inner class */

public class StudentProfile {
    Context context;


    /** Instantiate the interface and set the context */

    public StudentProfile(Context c) {
         context=c;
        }

    /** launch student activity */
    public void lauchProfile() {

         School.this.startActivity(new Intent(School.this, StudentProfile.class));
        //Intent intent = new Intent(School.this, StudentProfile.class);

        //startActivity(intent);

    }
}   

void webView(){
    String url = path +"student.php";   

    WebView wv = (WebView) findViewById(R.id.trivia_webview);
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);

    wv.addJavascriptInterface(new StudentProfile (this), "Student");

    wv.loadUrl(url);

    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // open URL in the web view itself
            if (url.contains(url))
                return super.shouldOverrideUrlLoading(view, url);
            // open URL in an external web browser
            else {

                return true;
            }
        }
    });
}

// rest of the code

注意:Web视图上有一个“学生”按钮,用于启动StudentProfile活动。

1 个答案:

答案 0 :(得分:3)

您的StudentProfile不是Activity,因此无法以此方式启动。它必须是一个单独的类,并在AndroidManifest.xml中声明。