java - Error: Could not find or load main class com.example.Test -


i searching how access private field of class other class , found can done using reflect.field in following code, when try execute code error saying :error: not find or load main class com.example.test

why happening?

test.java

package com.example;  import java.lang.reflect.*;  class test {     public static void main(string[] args)         // ease of throwaway test. don't         // normally!         throws exception     {         other t = new other();         t.setstr("hi");         field field = other.class.getdeclaredfield("str");         field.setaccessible(true);         object value = field.get(t);         system.out.println(value);     } } 

other.java

package com.example;  class other {     private string str;     public void setstr(string value)     {         str = value;     } } 

compile both classes using javac

javac other.java  javac test.java 

and run java test

while in eclipse need select test class using run configuration option.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -