0

I need help with the error that i'ev been getting when I'm trying to run the program into Android Studio. The app is a app page that lets the user upload any picture and saves it into the app after its uploaded and i need help with the errors that I've been getting.

This is my Java code (from @override to the end, I get an error "class or interface expected"):

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {


    EditText text = (EditText)findViewById(R.id.editText1);
    EditText text2 = (EditText)findViewById(R.id.editText2);



@Override
public void onClick(View v) {

final String name = text.getText().toString();
final String placeName = text2.getText().toString();

    String place = placeName.substring(0,3);
    String direct = name + place ;

    File folder = new File("/sdcard/CameraTest/" + direct + "/");
    folder.mkdirs();

    Intent myIntent = new Intent(CameraTestActivity.this, Press.class);
    myIntent.putExtra("key", "/sdcard/CameraTest/" + direct + "/");
    startActivity(myIntent);

    }
    });

This is my activity_upload.xml code:

?xml version="1.0" encoding="utf-8"?>

<LinearLayout  
xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<Button

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="Click To Upload File"

    android:id="@+id/uploadButton"

    />



<TextView

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text=""

    android:id="@+id/messageText"

    android:textColor="#000000"

    android:textStyle="bold"

    />

</LinearLayout>

And last but not least, this is the AndroidManifest.XML code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lediskodra.sendesigniii"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="25" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission   
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission   
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />

<application
    android:name="com.android.tools.fd.runtime.BootstrapApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.picupload.MainActivity"
        android:configChanges="orientation|screenSize|screenLayout"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" \
/>
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

</manifest>

1 Answers1

1

You need to close onCreate with a }. Put it after onClick

public class Foo {

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {


        EditText text = (EditText) findViewById(R.id.editText1);
        EditText text2 = (EditText) findViewById(R.id.editText2);


        @Override
        public void onClick(View v) {

            final String name = text.getText().toString();
            final String placeName = text2.getText().toString();

            String place = placeName.substring(0, 3);
            String direct = name + place;

            File folder = new File("/sdcard/CameraTest/" + direct + "/");
            folder.mkdirs();

            Intent myIntent = new Intent(CameraTestActivity.this, Press.class);
            myIntent.putExtra("key", "/sdcard/CameraTest/" + direct + "/");
            startActivity(myIntent);

        }

    });
 }
}
Drew Szurko
  • 1,601
  • 1
  • 16
  • 32
  • Hey I just did that but still getting errors (same one) Can you try and run it on your android studio and see what you get? – HoundsofJustice Feb 14 '17 at 20:16
  • Let me take a look, can you try editing your original post with the updated code? Please try to include your full class code, not just parts of it. – Drew Szurko Feb 14 '17 at 20:22
  • Hey Drew, that is the whole full code in the original post? Everytime I try to run it, I get 3 errors. Try pasting the code in the original post to android studio and see if you can find the error for it. Greatly appreciate any help! – HoundsofJustice Feb 14 '17 at 21:47
  • HoundsofJustic, I'm not sure if you left it out by accident, but your whole outer class was missing. Check out my edited answer, it works for me in Android Studio. – Drew Szurko Feb 15 '17 at 14:57