Load PowerPoint file in Android - java

I am trying to make a PPT viewer app.I have added the pptViewer library in my project from https://github.com/itsrts/pptviewer-android.
But I am getting an error called "cannot resolve symbol 'activity'" on this line pptViewer.loadPPT(activity,"/home/waheed/lab6.pptx").Please help.
Below is my code:
package com.example.waheed.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.itsrts.pptviewer.PPTViewer;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PPTViewer pptViewer = (PPTViewer) findViewById(R.id.pptviewer);
pptViewer.setNext_img(R.drawable.next)
.setPrev_img(R.drawable.prev)
.setSettings_img(R.drawable.settings)
.setZoomin_img(R.drawable.zoomin)
.setZoomout_img(R.drawable.zoomout);
pptViewer.loadPPT(activity,"/home/waheed/lab6.pptx");
}
}

activity isn't a defined symbol, but . In this case, since the code is in an activity, use the current object:
pptViewer.loadPPT(this, "/home/waheed/lab6.pptx");
You probably copy-pasted from the readme, as the activity used as sample method input in the readme means you have to pass an activity instance. You don't declare Activity activity = ..., but since you're in an activity you can use this

pptViewer.loadPPT(this,"/home/waheed/lab6.pptx");

Try this:
pptViewer.loadPPT(MainActivity.this,"/home/waheed/lab6.pptx");

You reference activity in your code which is not defined. Pass current class instead of the undefined field.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PPTViewer pptViewer = (PPTViewer) findViewById(R.id.pptviewer);
pptViewer.setNext_img(R.drawable.next)
.setPrev_img(R.drawable.prev)
.setSettings_img(R.drawable.settings)
.setZoomin_img(R.drawable.zoomin)
.setZoomout_img(R.drawable.zoomout);
pptViewer.loadPPT(MainActivity.this,"/home/waheed/lab6.pptx");
}

Related

did i call wrongly in android studio?

i am trying to use this answer but i don't get why am i getting this error:
error: class, interface, or enum expected
the code:
package com.example.moviereview3;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class HomeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
}
BottomNavigationView bottomNavigationView = BottomNavigationView)findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
sorry for asking so many dumb questions and thanks for answering
Do like this:-
public class HomeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
BottomNavigationView bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
}
}
You are missing a "(" right before casting the view, but even more importantly you're lacking to understand that the reference should be called inside the onCreate() method of the class. Placing stuff outside of the class would compromise proper form and prevent the compiler from recognizing and/or synthesizing the code you wrote, as such, the example you provided.
As an alternative, you could create a class member variable and then access it with the this operator, but most importantly make sure the code is inside the class scope.
private ...View bnv; ... this.bnv = instantiate
This would be your modified code, it's up to you if you want member variables vs local variables.
public class HomeActivity extends AppCompatActivity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
BottomNavigationView bottomNavigationView =
(BottomNavigationView)findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
} //END_ON_CREATE_METHOD
}/END_HOMEACTIVITY_CLASS

Can we call a method declared in same class in MainActivity not in onCreate or other methods in android studio?

I have created a method in MainActivity class. I know I can call that in onCreate method and other methods in that same class. But can I call that method outside onCreate and other methods but in MainActivity class?
When I try to do that, I get an error.
The error I am getting is "Invalid method declaration" but I have already declared the method below. I am just calling it here.
package com.example.android.kabaddicounter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
//Can we call this method here? Its giving an error
displayForPakistan(25);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void displayForPakistan(int score){
TextView scoreView = (TextView) findViewById(R.id.score_pakistan);
scoreView.setText(String.valueOf(score));
}
public void displayForIndia(int score){
TextView scoreView = (TextView) findViewById(R.id.score_india);
scoreView.setText(String.valueOf(score));
}
}
The answer is no you can't, unlike other codeflows the android codeflow runs only through callback functions called from the devices internal system.
You can for example call a method from other method but if that method will not be call from any of the callbacks , both will never get excited
With that been said, you have the exception of listener which can also call methods but there are just another type of callbacks
Read about activitys lifecycle to learn more

Android: Overriding onCreate method of main activity

I have a Java activity like so.
package com.xxx.yyy.overrideoncreate;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG","Original oncreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I wish to split some of the onCreate instructions to a separate class, so I created this too.
package com.xxx.yyy.overrideoncreate;
import android.os.Bundle;
import android.util.Log;
/**
* Created by oox on 26/6/17.
*/
public class SubClass extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG","Overridden");
super.onCreate(savedInstanceState);
}
}
I intend for subClass.onCreate to override MainActivity.onCreate -- both Overridden and original oncreate messages should be displayed. However, that did not seem to happen, the overridden message did not appear in the Logcat.
Any idea what I did wrong?
Thanks in advance.
In order for SubClass's onCreate to be called, an instance of SubClass should be created instead of an instance of MainActivity when the application is launched.
For that to happen, SubClass should become the actual main activity of your application (i.e. the activity class registered in the AndroidManifest.xml which gets launched when the application is launched).

Is findViewById() not be instanced?

I have a question about programming in android.
When I write a activity like this:
package com.mathquiz;
import android.widget.ImageButton;
public class ChooseMode extends ActionBarActivity {
private ImageButton easyButton=(ImageButton)findViewById(R.id.easy_button);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_mode);
easyButton.setVisibility(View.INVISIBLE);
}
The eclipse throws NullPointerException at line 4
However, if I assign "easyButton" in method onCreate, everything will be OK.
package com.mathquiz;
import android.widget.ImageButton;
public class ChooseMode extends ActionBarActivity {
private ImageButton easyButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_mode);
easyButton=(ImageButton)findViewById(R.id.easy_button);
easyButton.setVisibility(View.INVISIBLE);
}
Please help me to understand this problem.
It can't be "instanced" as you call it because in your first example, you haven't set a content view yet. Android's lifecycle methods have a specific order, that occur after the constructor is called.
The method works as expected, it just returns null because it has nothing to find at that current time.
Also, using an instance variable that requires using the current Activity as a Context will not work (In the below example, this refers to the ChooseMode instance).
Eg
public class ChooseMode extends ActionBarActivity {
private SharedPreferences = PreferenceManager.getDefaultSharedPreferences (this);
Will throw a NullPointerException down the line when used.
The layout is not defined on class variable definition. That's why it's a NullPointerException, because you haven't called setContentView(R.layout.activity_choose_mode); yet.
If you want to do that way, to avoid that amount of boilerplating, try RoboGuice. An example of a view could be this:
#ContentView(R.layout.main)
class RoboWay extends RoboActivity {
#InjectView(R.id.name) TextView name;
#InjectView(R.id.thumbnail) ImageView thumbnail;
#InjectResource(R.drawable.icon) Drawable icon;
#InjectResource(R.string.app_name) String myName;
#Inject LocationManager loc;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
name.setText( "Hello, " + myName );
}
}
More examples and tutorials are here.

shipp-sliding-menu android slider error

I am trying to implement facebook like slider, and i am planning to user below opensource code
https://github.com/leonardosalles/shipp-sliding-menu
but after i integrate, i created a sample activity
as per the code guide, in the
PrincipalActivity.java
//intent = new Intent(this, MyNewActivity2.class);
if it try giving my class, i get below error
cannot find symbol constructor Intent(,java.lang.Class)
here is my activity class
import android.app.Activity;
import android.os.Bundle;
public class SampleFirstTest extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
please Help me to resolve the issue, i am new to android..
add SampleFirstTest in your AndroidManifest.xml

Categories