I am trying to know whether the path I am mentioning is the path of file or folder.
Here is the code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File f=new File("F:/Office/A.txt");
boolean b=f.isFile();
Toast.makeText(this,""+b,Toast.LENGTH_LONG).show();
}
}
But it if giving false inspite of the fact that I am giving the right path. The same code in eclipse is giving true but in Android Studio is giving false. Why so?
try this:
String s = f.getAbsolutePath();'
then switch your Toast to this:
Toast.makeText(this, s,Toast.LENGTH_LONG).show();
that way the Toast will show you the path, and you can proceed from there
Related
I am trying to Print some messages using Log.i but it doesn't print anything, the problem starts after I updated the Android studio.
How can I solve the problem?
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("check","**************checking");
setContentView(R.layout.activity_main);
}
}
An alternate solution, but it's not the best.
System.out.print();
Make sure you select the device you are using, you can do it on the top left side of the Logcat.
for example if you used an emulator and than a device make sure the device is selected.
Try using the tag constant
public static final string TAG = "MainActivity"
Then do
Log.d(TAG, YOURMESSAGE)
Also as an alternative you can use System.out
I get an error in debugging and I can't set this boolean value. I attached a screenshot of the error.
I call DeviceUpdateManager in my mainActivity like this:
public class MainActivity extends AppCompatActivity implements DeviceUpdateManager.OnDataCOM {
DeviceUpdateManager deviceUpdateManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.deviceUpdateManager = new DeviceUpdateManager(this.serverCOM,this.getApplicationContext(),this);
}
etc...
}
I cannot find the error... Is it related to the passing Context in another class?
EDIT:SOLVED
I reboot the PC and restarted Android Studio and everything worked great.
It happens when you changed variable name in code and running application with older name in code.
Remove below snippet from Project/build.gradle file.
minifyEnabled true
Please have a look at this link for more info.
https://stackoverflow.com/a/45281798/5870824
So,that's the logcat information I get.The app still can run,but I want to know the reason why I get this error.
I don't understand why i get this so i even don't know how to ask.
09-26 07:13:33.510 18533-18533/com.gongxxing.gongxxing0921 D/AccessibilityManager﹕ setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
java.lang.Throwable: setStateLocked
at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
at android.view.View.setFlags(View.java:9941)
at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
at android.view.ViewGroup.<init>(ViewGroup.java:525)
at android.view.ViewGroup.<init>(ViewGroup.java:520)
at android.view.ViewGroup.<init>(ViewGroup.java:516)
at android.view.ViewGroup.<init>(ViewGroup.java:512)
at android.widget.FrameLayout.<init>(FrameLayout.java:119)
at com.android.internal.policy.impl.PhoneWindow$DecorView.<init>(PhoneWindow.java:2341)
at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3639)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:4026)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:2052)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
at com.gongxxing.gongxxing0922.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:6142)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
I am sorry for forgetting paste the Main activity.
The line 27 is
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState); is the line 27.
Sorry to answer this old question,but i solved this exception in my project.
I think what leads to the exception is we are using the context of our activity when it is creating.
My code is something like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
regToWx();
}
private void regToWx(){
IWXAPI api;
api = WXAPIFactory.createWXAPI(this, Constants.WX_APP_ID, true);
api.registerApp(Constants.WX_APP_ID);
String text = "123";
WXTextObject textObj = new WXTextObject();
textObj.text = text;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.description = text;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.scene = SendMessageToWX.Req.WXSceneSession;
req.transaction = String.valueOf(System.currentTimeMillis());
req.message = msg;
api.sendReq(req);
}
As the regToWx method need to create something by this which is the context,but i think the context can not be used(in some ways) inside onCreate method. So I just put it in a thread and then the problem is solved.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new Runnable() {
#Override
public void run() {
regToWx();
}
}).start();
}
So try to find out what you have done with your context in onCreate method, put these code out of the it or just make the code asynchronous.
I was getting the same error. I found out that it is due to the attribute android:sharedUserId="com.something" that I was using in the manifest files.
Suppose version 1 of your application has android:sharedUserId in the manifest and initialises a ContentProvider.
Now, suppose in version 2, you remove the android:sharedUserId from the manifest and try to access the ContentProvider created in version 1.
In this case, the recent version will not be able to access the ContentProvider created in version 1.
Hi I am doing one application here I neeed to convert .doc file to pdf file,i tried but no idea any one did before please suggest me...thankyou
public class ShootAndCropActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
You might have good luck with this lib, available on GitHub. A how-to is presented in the article.
The following code was copied from project one and pasted into project two. No errors in project one. In project two I get:
The method onClick(View) of type new View.OnClickListener((){} must override a superclass method
implements androd.view.View.OnClickListener.onClick
The project settings look the same, but I must be missing something.
private Button mCompany = null;
public class About extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
setTitle(R.string.title_about);
mCompany = (Button)findViewById(R.id.about_company_button);
mCompany.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getResources().getString(R.string.app_company_website)));
startActivity(intent);
}
});
Found a solution on another site but I would like to know why this will work. It said to comment out the Override. Actually, it now compiles fine but crashes when the about item is clicked.