當我嘗試將程序運行到Android Studio時,我需要獲得幫助。該應用程序是一個應用程序頁面,可讓用戶上傳任何圖片並在上傳後將其保存到應用程序中,並且我需要獲取有關我收到的錯誤的幫助。Android Studio - 代碼中的錯誤
這是我的Java代碼(來自@覆蓋到了最後,我得到一個錯誤 「類或接口預期」):
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);
}
});
這是我的activity_upload.xml代碼:
?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>
最後但並非最不重要的,這是AndroidManifest.xml中的代碼:
<?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>
不要忘記實際的錯誤信息。 – AntonH
您錯過了onCreate結尾處的}。在onClick結束時,儘管這可能只是停止複製粘貼的地方。 –
[類或接口預期]的可能的重複(http://stackoverflow.com/questions/28978782/class-or-interface-expected) –