Reputation: 62444
I'm trying to learn Java, I know this is a noob question, but bear with me please :)
Ctrl+Shift+O isn't loading my other .java file I created and I'm not sure how to tell it to. The file is called "MyWebViewClient.java". I'm also wondering, if I were to put this file within a folder, would it change how it's imported?
package com.myPackage;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MyPackageClass extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//init webview
WebView DCWebView = (WebView) findViewById(R.id.webview);
WebSettings webViewSettings = DCWebView.getSettings();
//when a link is clicked, use the WebView instead of opening a new browser
DCWebView.setWebViewClient(new MyWebViewClient());
//enable javascript
webViewSettings.setJavaScriptEnabled(true);
}
}
Both classes are part of the package com.myPackage;
package... I'm not entirely sure when I should change the name of a package. They're also siblings of each other within /src
Upvotes: 0
Views: 956
Reputation: 563
in your project you should have a src folder
in src you have your package structure so...
-src
--com
---myPackage
----MyPackageClass.java
----<Put second class here>
you dont need to import the second java class if its in the same package
Upvotes: 1
Reputation:
Where is the MyWebViewClient.java
file now? Also, what package declaration are you using in MyWebViewClient.java
?
If the MyWebViewClient.java
file is within the same package structure, you shouldn't have any problem loading it (by same package structure I mean in the same set of folders starting with com.myPackage
.
If it is not, than you will have to tell eclipse about the other projects or folders you want on your build path. While this is in answer to a php question, this should be what you are looking for.
Upvotes: 2
Reputation: 1098
May I ask are the java files in the same package ? Classes can be reached they are in the same package.
Upvotes: 0